<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();


/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：tudougeaini
 邮箱：877873666@qq.com

 **** 版权所有 **** */



//用户检测
$MB->Open(',MB_realname','login',2);


switch ($mudi){
	case 'add':
		$menuFileID = 353;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		AddOrRev();
		break;

	case 'rev':
		$menuFileID = 354;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		AddOrRev();
		break;

	case 'moreDeal':
		$menuFileID = 354;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		MoreDeal();
		break;

	case 'moreDel':
		$menuFileID = 355;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		MoreDel();
		break;

	case 'checkVpsName':
		CheckVpsName();
		break;

	case 'sync':
		$menuFileID = 354;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		sync();
		break;

	case 'import':
		$menuFileID = 356;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		ImportDeal();
		break;

	case 'loadInfo':
		$menuFileID = 356;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		LoadInfo();
		break;

	case 'getList':
		GetList();
		break;

	case 'useTestCode':
		$menuFileID = 354;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		UseTestCode();
		break;

	case 'checkKaitong':
		$menuFileID = 354;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		CheckKaitong();
		break;

	case 'updateWorkInfo':
		$menuFileID = 354;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		UpdateWorkInfo();
		break;

	case 'tixingDeal':
		$menuFileID = 359;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		TixingDeal();
		break;

	case 'export':
		$menuFileID = 351;
		$MB->IsSecMenuRight('alertClose',$menuFileID,$dataType);
		ExportDeal();
		break;

	case 'getBaoxiaoOrder':
		$menuFileID = 351;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		GetBaoxiaoOrder();
		break;

	case 'updateApiID':
		$menuFileID = 351;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		UpdateApiID();
		break;

	case 'apiUpdate':
		ApiUpdate();
		break;

	default:
		die('err');
}

$MB->Close();
$DB->Close();





// 添加与修改
function AddOrRev(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN;

	@ini_set('max_execution_time', 0);
	@set_time_limit(0); 

	$backURL		= OT::PostStr('backURL');
	$dataType		= OT::PostStr('dataType');
	$dataTypeCN		= OT::PostStr('dataTypeCN');
	$dataID			= OT::PostInt('dataID');

	$userIdOld		= OT::PostInt('userIdOld');
	$usernameOld	= OT::PostStr('usernameOld');
	$classID		= OT::PostInt('classID');
	$prefName		= OT::PostStr('prefName');
	$useNum			= OT::PostInt('useNum');
	$numLen			= OT::PostInt('numLen');

	$apiID			= OT::PostInt('apiID');
	$proDataID		= OT::PostInt('proDataID');
		$prs = $DB->GetRow('select VAD_theme,VAD_companyID from '. OT_dbPref .'vpsApiData where VAD_ID='. $proDataID);
		$proDataName	= $prs['VAD_theme'];
		$companyID		= $prs['VAD_companyID'];
		unset($prs);
	$username		= OT::PostStr('username');
	$comServID		= OT::PostInt('comServID');
	$vpsName		= OT::PostStr('vpsName');
	$isAutoName		= OT::PostInt('isAutoName');
	$vpsPwd			= OT::PostStr('vpsPwd');
	$system			= OT::PostStr('system');
	$payMode		= OT::PostStr('payMode');
	$userPrice		= OT::PostFloat('price');
	$userCost		= OT::PostFloat('cost');
	$moneyNote		= OT::PostStr('moneyNote');
	$note			= OT::PostStr('note');
	$isUserPay		= OT::PostInt('isUserPay');
	$adminNote		= OT::PostStr('adminNote');

	// $apiID = 0 无接口机器专属信息
	$typeID			= OT::PostInt('typeID');
	$time			= OT::PostStr('time');
		if (! strtotime($time)){ $time = TimeDate::Get(); }
	$ipStr			= OT::PostStr('ipStr');
	$vpsEndTime		= OT::PostStr('vpsEndTime');
	$state			= OT::PostInt('state');

	if ($proDataID==0 || strlen($vpsName)==0 || strlen($vpsPwd)==0 || strlen($payMode)==0 || (in_array($payMode,array('24hour','48hour'))==false && $userPrice==0)){
		JS::AlertBackEnd('表单内容接收不全');
	}

	if (IdcInfo::VpsSystem($system) == 'linux'){
		$vpsPort	= '22';
		$vpsUser	= 'root';
	}else{
		$vpsPort	= '3389';
		$vpsUser	= 'administrator';
	}

	$alertStr = '';
	$userID = 0;
	$userMoney = -9;
	$recomId = 0;
	$recomUser = '';
	if ((strlen($username) > 0 && $usernameOld != $username) || $isUserPay == 1){
		$userexe = $DB->QueryParam('select UE_ID,UE_recomId,UE_recomUser,UE_money from '. OT_dbPref .'users where UE_username=?',array($username));
			if (! $row = $userexe->fetch()){
				JS::AlertBackEnd('检测不到用户信息');
			}
		$userID		= $row['UE_ID'];
		$recomId	= $row['UE_recomId'];
		$recomUser	= $row['UE_recomUser'];
		$userMoney	= floatval($row['UE_money']);
		if ($isUserPay==1){
			if ($userMoney - $userPrice < 0){
				JS::AlertBackEnd('用户余额'. $userMoney .'元，扣款'. $userPrice .'元，余额不足，没法扣款。');
			}else{
				$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money-'. $userPrice,'UE_payMoney'=>'UE_payMoney+'. $userPrice),'UE_ID='. $userID);
				if (! $result){ JS::AlertBackEnd('用户余额扣款失败，请刷新页面重试下。'); }
			}
		}
		unset($userexe);
	}else{
		$userID = $userIdOld;
		if ($userID > 0){
			$urs = $DB->GetRow('select UE_recomId,UE_recomUser,UE_money from '. OT_dbPref .'users where UE_ID='. $userID);
			$recomId	= $urs['UE_recomId'];
			$recomUser	= $urs['UE_recomUser'];
			$userMoney	= floatval($urs['UE_money']);
			unset($urs);
		}
	}

	$chkexe = $DB->QueryParam('select VAU_ID from '. OT_dbPref .'vpsApiUsers where VAU_vpsName=? limit 1',array($vpsName));
	if ($chkexe->fetch()){
		if ($isAutoName == 1){
			$vpsNameArr = IdcArea::GetNewVpsName('vpsApi',$classID);
			$useNum = $vpsNameArr['useNum'];
			$vpsName = $vpsNameArr['vpsName'];
			$alertStr .= '\n机器编码已被占用，自动重名为 '. $vpsName;
		}else{
			JS::AlertBackEnd('机器编码已被占用，请更换个');
		}
	}
	unset($chkexe);

	$record=array();
	if ($apiID == 0){
		$record['VAU_type']		= 'pro';
		$record['VAU_ipStr']	= $ipStr;
	}else{
		$record['VAU_type']		= 'api';
	}
	$record['VAU_companyID']	= $companyID;
	$record['VAU_proDataID']	= $proDataID;
	$record['VAU_proDataName']	= $proDataName;
	$record['VAU_userID']		= $userID;
	$record['VAU_username']		= $username;
	$record['VAU_comServID']	= $comServID;
	$record['VAU_vpsName']		= $vpsName;
	$record['VAU_vpsPort']		= $vpsPort;
	$record['VAU_vpsUser']		= $vpsUser;
	$record['VAU_vpsPwd']		= Encrypt::SyEnDe('en',$vpsPwd);
	$record['VAU_system']		= $system;
	$record['VAU_payMode']		= $payMode;
	$record['VAU_price']		= $userPrice;
	$record['VAU_cost']			= $userCost;
	$record['VAU_note']			= $note;
	$record['VAU_isUserPay']	= $isUserPay;
	$record['VAU_adminNote']	= $adminNote;

	$addrec=$DB->query('select * from '. OT_dbPref .'vpsApiUsers where VAU_ID='. $dataID);
	if (! $row = $addrec->fetch()){
		$alertMode='添加';

		if ($apiID == 0){
			$endTime = IdcArea::NewEndTime($payMode, $time);
			if (! strtotime($vpsEndTime)){ $vpsEndTime = $endTime; }
			$record['VAU_time']			= $time;
			$record['VAU_vpsEndTime']	= $vpsEndTime;
			$record['VAU_state']		= 10;
		}else{
			$todayTime = TimeDate::Get();
			$endTime = IdcArea::NewEndTime($payMode, $todayTime);
			$record['VAU_time']			= $todayTime;
			$record['VAU_state']		= 3;
		}

		$record['VAU_endTime']		= $endTime;
		$record['VAU_adminID']		= $MB->mUserID;
		$record['VAU_adminName']	= $MB->mMbRow['MB_realname'];
		$judRes = $DB->InsertParam('vpsApiUsers',$record);
	}else{
		JS::AlertBackEnd('禁止修改');
		// $alertMode='修改';
		// $judRes = $DB->UpdateParam('vpsApiUsers',$record,'VAU_ID='. $dataID);
	}
	unset($addrec);

	if ($judRes){
		$alertRes='成功';
		if ($alertMode == '添加'){
			if ($useNum > 0){ $DB->UpdateParam('vpsClass',array('VC_useNum'=>$useNum),'VC_ID='. $classID); }
			if ($userID > 0){ $DB->UpdateParam('users',array('UE_vpsApiNum'=>'UE_vpsApiNum+1'),'UE_ID='. $userID); }

			$dataID = $DB->GetOne('select max(VAU_ID) from '. OT_dbPref .'vpsApiUsers where VAU_userID='. $userID);
			if ($apiID == 0){
				$retArr = array('res'=>true,'note'=>'');
				$noteAddi = 'IP地址：'. $ipStr .'；';
			}else{
				$retArr = AppIdcVps::Kaitong($dataID);
				$noteAddi = '';
			}
			if ($retArr['res']){
				if ($isUserPay == 0){
					if ($userMoney != -9){ $userMoney += $userPrice; }
					$scoreArr = array();
					$scoreArr['MR_userID']		= $userID;
					$scoreArr['MR_username']	= $username;
					$scoreArr['MR_dataID']		= $dataID;
					$scoreArr['MR_dataName']	= $vpsName;
					$scoreArr['MR_type']		= 'suff';
					$scoreArr['MR_type2']		= '后台充值';
					$scoreArr['MR_money']		= $userPrice;
					$scoreArr['MR_remMoney']	= $userMoney;
					$scoreArr['MR_bank']		= '账户余额';
					$scoreArr['MR_note']		= '后台充值成功！充值金额：'. $userPrice .'元，备注：'. $moneyNote;
					$scoreArr['MR_adminID']		= $MB->mMbRow['MB_ID'];
					$scoreArr['MR_adminName']	= $MB->mMbRow['MB_realname'];
					$mrRes = AppMoneyRecord::AddData($scoreArr);
				}

				$userGain = $userPrice - $userCost;
				if ($userGain < 0){ $userGain = 0; }
				if ($userMoney != -9){
					$userMoney -= $userPrice;
					$alertStr .= '\n用户：'. $username .'，扣款：'. $userPrice .' 元，余额：'. $userMoney;
				}else{
					$alertStr .= '\n用户：无，扣款：'. $userPrice .' 元';
				}
				$scoreArr = array();
				$scoreArr['MR_userID']		= $userID;
				$scoreArr['MR_username']	= $username;
				$scoreArr['MR_dataID']		= $dataID;
				$scoreArr['MR_dataName']	= $vpsName;
				$scoreArr['MR_type']		= 'vpsApi';
				$scoreArr['MR_type2']		= '开通';
				$scoreArr['MR_money']		= $userPrice*(-1);
				$scoreArr['MR_remMoney']	= $userMoney;
				$scoreArr['MR_cost']		= $userCost;
				$scoreArr['MR_gain']		= $userGain;
				$scoreArr['MR_bank']		= '账户余额';
				$scoreArr['MR_note']		= '后台开通成功！产品：'. $proDataName .'；机器编码：'. $vpsName .'；'. $noteAddi .'付款方式：'. IdcInfo::PayMode($payMode) .'（'. TimeDate::Get('date',$endTime) .'到期）；价格：'. $userPrice .'元；';
				$scoreArr['MR_adminID']		= $MB->mMbRow['MB_ID'];
				$scoreArr['MR_adminName']	= $MB->mMbRow['MB_realname'];
				$mrRes = AppMoneyRecord::AddData($scoreArr);
					if ($mrRes){ $mrAlertStr=''; }else{ $mrAlertStr='\n财务信息记录失败（需要“财务基础包”插件支持）！'; }
				$alertStr .= $mrAlertStr;

				if ($apiID > 0){
					$alertStr .= '\n上级API开通成功！'. $retArr['note'];
				}

				// 如有推荐人，推荐人推广佣金处理
				$vpsSysArr = Cache::PhpFile('vpsSys');
				if ($recomId > 0 && strpos($vpsSysArr['VS_commArea'],'|vpsApiKaiAdmin|') !== false){
					$urs = $DB->GetRow('select UE_makeMoney,UE_makingMoney from '. OT_dbPref .'users where UE_ID='. $recomId);
					$makeMoney	= floatval($urs['UE_makeMoney']);
					$makingMoney= floatval($urs['UE_makingMoney']);
					unset($urs);

					$proPrice	= abs($userPrice);
					$money = $proPrice * $vpsSysArr['VS_vpsApiKaiRate'];
					if ($money > $vpsSysArr['VS_vpsApiKaiMax']){ $money = $vpsSysArr['VS_vpsApiKaiMax']; }
					$proArr = array(
						'GI_source'			=> '后台',
						'GI_userID'			=> $recomId,
						'GI_username'		=> $recomUser,
						'GI_proUserID'		=> $userID,
						'GI_proUsername'	=> $username,
						'GI_proType'		=> 'vpsApi',
						'GI_proID'			=> $dataID,
						'GI_proName'		=> $proDataName,
						'GI_proPrice'		=> $proPrice,
						'GI_vpsName'		=> $vpsName,
						'GI_endTime'		=> $endTime,
						'GI_mode'			=> '开通',
						'GI_rate'			=> $vpsSysArr['VS_vpsApiKaiRate'],
						'GI_money'			=> $money,
						);
					$listArr = array(
						'GH_makingMoney'	=> $makingMoney + $money,
						'GH_makeMoney'		=> $makeMoney,
						);
					AppGain::AddItemData($proArr, $listArr);
				}
			}else{
				if ($isUserPay==1){
					$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money+'. $userPrice,'UE_payMoney'=>'UE_payMoney-'. $userPrice),'UE_ID='. $userID);
					if (! $result){ JS::AlertBackEnd('用户余额扣款失败，请刷新页面重试下。'); }
				}
				$alertStr .= '\n上级API开通失败！'. $retArr['note'];
			}
		}
	}else{
		if ($isUserPay==1){
			$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money+'. $userPrice,'UE_payMoney'=>'UE_payMoney-'. $userPrice),'UE_ID='. $userID);
			if (! $result){ JS::AlertBackEnd('用户余额扣款失败，请刷新页面重试下。'); }
		}
		$alertRes='失败';
	}

	Adm::AddLog(array(
		'theme'	=> $proDataName,
		'note'	=> '【'. $dataTypeCN .'】'. $alertMode . $alertRes .'！',
		));

	JS::AlertHref(''. $alertMode . $alertRes .'！'. $alertStr,$backURL);
}



// 检测服务器名
function CheckVpsName(){
	global $DB;

	$vpsName	= OT::GetStr('vpsName');

	if (strlen($vpsName) <= 3){
		die('alert("名称太短了，只是要4位数");');
	}

	$chkexe = $DB->QueryParam('select VAU_ID from '. OT_dbPref .'vpsApiUsers where VAU_vpsName=?',array($vpsName));
	if ($chkexe->fetch()){
		die('alert("已被占用");');
	}else{
		die('alert("恭喜！未被占用");');
	}
	unset($chkexe);
}


// 批量操作处理
function MoreDeal(){
	global $DB,$MB;

	@ini_set('max_execution_time', 0);
	@set_time_limit(0); 

	$mudi2	= OT::GetStr('mudi2');
	$backURL= OT::PostStr('backURL');
	$dataID	= OT::PostInt('dataID');
	$apiID	= OT::PostInt('apiID');
		if ($dataID <= 0){
			JS::AlertBackEnd('该记录ID错误.');
		}

	$alertStr = '';
	switch ($mudi2){
		// 修改已分配IP地址
		case 'ipStr':
			$ipStr = OT::PostStr('ipStr');
			$result = $DB->UpdateParam('vpsApiUsers',array('VAU_ipStr'=>$ipStr),'VAU_ID='. $dataID);
			if ($result){
				$alertRes='成功';
			}else{
				$alertRes='失败';
			}
			$alertStr = '修改已分配IP地址'. $alertRes .'！';
			break;
	
		// 更改数据库中的状态
		case 'state':
			$newState = OT::PostInt('newState',-1);
			if (! in_array($newState,array(0,3,5,6,8,9,10,12,15))){
				JS::AlertBackEnd('新状态值错误.');
			}
			$result = $DB->UpdateParam('vpsApiUsers',array('VAU_state'=>$newState),'VAU_ID='. $dataID);
			if ($result){
				$alertRes='成功';
			}else{
				$alertRes='失败';
			}
			$alertStr = '设置状态'. $alertRes .'！';
			break;

		// 修改资料
		case 'ziliao':
			$system		= OT::PostStr('system');
			$isRevInfo	= OT::PostInt('isRevInfo');
			$vpsPort	= OT::PostInt('vpsPort');
			$vpsUser	= OT::PostStr('vpsUser');
			$vpsPwd		= OT::PostStr('vpsPwd');
			$note		= OT::PostStr('note');
			$isAutoXufei= OT::PostInt('isAutoXufei');
			$adminNote	= OT::PostStr('adminNote');
			$weixinTime	= OT::PostStr('weixinTime');
			$useMenuStr	= OT::PostArrStr('useMenuStr',',');
			$event		= OT::PostArrStr('event',',');

			$dataArr = array();
			$dataArr['VAU_system']		= $system;
			if ($isRevInfo == 1){
				$dataArr['VAU_vpsPort']		= $vpsPort;
				$dataArr['VAU_vpsUser']		= $vpsUser;
				$dataArr['VAU_vpsPwd']		= Encrypt::SyEnDe('en',$vpsPwd);
			}
			$dataArr['VAU_isAutoXufei']	= $isAutoXufei;
			$dataArr['VAU_note']		= $note;
			$dataArr['VAU_adminNote']	= $adminNote;
			$dataArr['VAU_useMenuStr']	= $useMenuStr;
			$dataArr['VAU_event']		= $event;
			if (strtotime($weixinTime)){ $dataArr['VAU_weixinTime'] = $weixinTime; }
			$result = $DB->UpdateParam('vpsApiUsers', $dataArr, 'VAU_ID='. $dataID);
			if ($result){
				$alertRes='成功';
			}else{
				$alertRes='失败';
			}
			$alertStr = '修改资料'. $alertRes .'！';
			break;
	
		// 转移到新用户名
		case 'username':
			$username		= OT::PostStr('username');
			$usernameOld	= OT::PostStr('usernameOld');
			if ($username == $usernameOld){
				JS::AlertBackEnd('你要迁移的新用户名就是当前用户名，无需重复操作.');
			}
			$userexe = $DB->QueryParam('select UE_ID,UE_username from '. OT_dbPref .'users where UE_username=?',array($username));
			if (! $row = $userexe->fetch()){
				JS::AlertBackEnd('检测不到新用户信息，请检查你输入的用户名是否存在.');
			}

			$dataArr = array(
				'VAU_userID'	=> $row['UE_ID'],
				'VAU_username'	=> $row['UE_username']
				);
			$result = $DB->UpdateParam('vpsApiUsers', $dataArr, 'VAU_ID='. $dataID);
			if ($result){
				$alertRes='成功';
			}else{
				$alertRes='失败';
			}
			$alertStr = '转移到新用户名'. $alertRes .'！';
			break;
	
		// 实名认证 - 关联认证
		case 'auth':
			$workId		= OT::PostStr('workId');	// 当前机器业务编码
			$proWorkID	= OT::PostStr('proWorkID');	// 已认证的机器业务编码
			if (empty($workId) || empty($proWorkID)){
				JS::AlertBackEnd('业务编号不能为空（'. $workId .'|'. $proWorkID .')');
			}

			$retArr = AppIdcVps::Auth($dataID, $proWorkID);
			if ($retArr['res']){
				$alertStr .= '\n实名认证关联成功！';
				AppIdcHost::Sync($dataID,'api');	// 同步更新API信息
			}else{
				if (strpos($retArr['note'],':3218}') !== false){
					$alertStr .= '\n实名认证关联处理中！';
					AppIdcHost::Sync($dataID,'api');	// 同步更新API信息
				}else{
					$alertStr .= '\n实名认证关联失败！'. $retArr['note'];
					JS::AlertBackEnd($alertStr);
				}
			}
			JS::AlertHref($alertStr,$backURL);
			break;
	
		// 单独设置它的续费价格
		case 'newPrice':
			$isNewPrice		= OT::PostInt('isNewPrice');
			$priceMonth		= OT::PostFloat('priceMonth');
			$costMonth		= OT::PostFloat('costMonth');
			$price3Month	= OT::PostFloat('price3Month');
			$cost3Month		= OT::PostFloat('cost3Month');
			$price6Month	= OT::PostFloat('price6Month');
			$cost6Month		= OT::PostFloat('cost6Month');
			$priceYear		= OT::PostFloat('priceYear');
			$costYear		= OT::PostFloat('costYear');
			if ($priceMonth==0 || $price3Month==0 || $price6Month==0 || $priceYear==0){
				JS::AlertBackEnd('续费价格不能有为空或为0\n\n　月付：'. $priceMonth .' 元\n　季付：'. $price3Month .' 元\n半年付：'. $price6Month .' 元\n　年付：'. $priceYear .' 元');
			}

			$chkexe = $DB->Select('vpsApiUsers', 'VAU_isNewPrice,VAU_proDataID,VAU_payMode,VAU_price', 'VAU_ID='. $dataID);
			if (! $row = $chkexe->fetch()){
				JS::AlertBackEnd('该机器记录不存在.');
			}

			$dataArr = array(
				'VAU_isNewPrice'	=> $isNewPrice,
				'VAU_priceMonth'	=> $priceMonth,
				'VAU_costMonth'		=> $costMonth,
				'VAU_price3Month'	=> $price3Month,
				'VAU_cost3Month'	=> $cost3Month,
				'VAU_price6Month'	=> $price6Month,
				'VAU_cost6Month'	=> $cost6Month,
				'VAU_priceYear'		=> $priceYear,
				'VAU_costYear'		=> $costYear
				);
			if ($isNewPrice == 1){
				$priceArr = array(
					'priceMonth'	=> $priceMonth,
					'price3Month'	=> $price3Month,
					'price6Month'	=> $price6Month,
					'priceYear'		=> $priceYear,
					'costMonth'		=> $costMonth,
					'cost3Month'	=> $cost3Month,
					'cost6Month'	=> $cost6Month,
					'costYear'		=> $costYear
					);
				$newPrice = IdcInfo::VpsPayPrice($row['VAU_payMode'], $priceArr, '');
				$newCost = IdcInfo::VpsPayCost($row['VAU_payMode'], $priceArr, '');
				if ($newPrice <= 0 || $newCost <= 0){
					JS::AlertBackEnd('当前付款方式：'. IdcInfo::PayMode($row['VAU_payMode']) .' 不支持设置独立续费价格');
				}
				$dataArr['VAU_price']	= $newPrice;
				$dataArr['VAU_cost']	= $newCost;

			}elseif ($isNewPrice == 0 && $row['VAU_isNewPrice'] != $isNewPrice){
				$proexe = $DB->Select('vpsApiData', 'VAD_priceMonth, VAD_price3Month, VAD_price6Month, VAD_priceYear, VAD_price2Year, VAD_price3Year, VAD_price4Year, VAD_price5Year, VAD_costMonth, VAD_cost3Month, VAD_cost6Month, VAD_costYear, VAD_cost2Year, VAD_cost3Year, VAD_cost4Year, VAD_cost5Year', 'VAD_ID='. $row['VAU_proDataID']);
				$rs = $proexe->fetch();
				$newPrice = IdcInfo::VpsPayPrice($row['VAU_payMode'], $rs, 'VAD_');
				$newCost = IdcInfo::VpsPayCost($row['VAU_payMode'], $rs, 'VAD_');
				if ($newPrice <= 0 || $newCost <= 0){
					JS::AlertBackEnd('当前付款方式：'. IdcInfo::PayMode($row['VAU_payMode']) .' 不支持取消设置独立续费价格');
				}
				$dataArr['VAU_price']	= $newPrice;
				$dataArr['VAU_cost']	= $newCost;
			}

			$result = $DB->UpdateParam('vpsApiUsers', $dataArr, 'VAU_ID='. $dataID);
			if ($result){
				$alertRes='成功';
			}else{
				$alertRes='失败';
			}

			$alertStr = '单独设置续费价格'. $alertRes .'！';
			break;
	
		// 转正
		case 'zhuanzheng':
			$payMode	= OT::PostStr('payMode');
			$isApi		= OT::PostInt('isApi');

			$dataexe = $DB->query('select VAU_userID,VAU_apiID,VAU_username,VAU_time,VAU_endTime,VAU_proDataID,VAU_proDataName,VAU_vpsName,VAU_payMode,VAU_isNewPrice,VAU_priceYear,VAU_costYear from '. OT_dbPref .'vpsApiUsers where VAU_ID='. $dataID);
			if (! $row = $dataexe->fetch()){ JS::AlertBackEnd('该记录不存在。'); }
			$apiID			= $row['VAU_apiID'];
			$startTime		= $row['VAU_time'];
	//		$endTime		= $row['VAU_endTime'];
			$userID			= $row['VAU_userID'];
			$username		= $row['VAU_username'];
			$proDataName	= $row['VAU_proDataName'];
			$vpsName		= $row['VAU_vpsName'];
			if ($row['VAU_payMode'] == '24hour'){
				$payMode = 'month';
			}elseif ($row['VAU_payMode'] == '48hour'){
				$payMode = 'year';
			}else{
				JS::AlertBackEnd('之前付款方式不对（'. $row['VAU_payMode'] .'）。');
			}
	//			if (! strtotime($endTime)){
	//				JS::AlertBackEnd('到期时间获取异常（'. $endTime .'），请刷新页面后重新操作下。');
	//			}

			$endTime = IdcArea::NewEndTime($payMode, $startTime);

			$alertStr = '';

			if ($isApi == 1 && $apiID > 0){
				$retArr = AppIdcVps::Zhuanzheng($payMode,$endTime,$dataID);
				if (! $retArr['res']){
					JS::AlertBackEnd('API转正失败，请联系管理员给你处理！'. $retArr['note']);
				}

			}else{
				$newArr = array();
				$newArr['VAU_payMode']		= $payMode;
				$newArr['VAU_vpsEndTime']	= $endTime;
				$newArr['VAU_endTime']		= $endTime;
				$newArr['VAU_state']		= 10;
				$retRes = $DB->UpdateParam('vpsApiUsers',$newArr,'VAU_ID='. $dataID);
				if (! $retRes){
					JS::AlertBackEnd('手动转正失败，请联系管理员给你处理！');
				}

			}

			$scoreArr = array();
			$scoreArr['MR_userID']		= $userID;
			$scoreArr['MR_username']	= $username;
			$scoreArr['MR_dataID']		= $dataID;
			$scoreArr['MR_dataName']	= $vpsName;
			$scoreArr['MR_type']		= 'vpsApi';
			$scoreArr['MR_type2']		= '转正';
			$scoreArr['MR_money']		= 0;
			$scoreArr['MR_remMoney']	= -9;
			$scoreArr['MR_note']		= '后台转正成功！产品：'. $proDataName .'；机器编码：'. $vpsName .'；转正期限：'. IdcInfo::PayTime($payMode) .'（'. TimeDate::Get('date',$endTime) .'到期）；';
			$scoreArr['MR_adminID']		= $MB->mMbRow['MB_ID'];
			$scoreArr['MR_adminName']	= $MB->mMbRow['MB_realname'];
			$mrRes = AppMoneyRecord::AddData($scoreArr);
				if (! $mrRes){ $alertStr .= '\n财务信息记录失败（需要“财务基础包”插件支持）！'; }

			$alertStr = '转正成功！'. $alertStr;
			break;

		// 续费
		case 'xufei':
			$payMode		= OT::PostStr('payMode');
			$isUserPay		= OT::PostInt('isUserPay');
			$userPrice		= OT::PostFloat('userPrice');
			$userCost		= OT::PostFloat('userCost');
			$moneyNote		= OT::PostStr('moneyNote');
			$timeObj		= OT::PostInt('timeObj');
			$apiObj			= OT::PostInt('apiObj');

			$dataexe = $DB->query('select VAU_apiID,VAU_userID,VAU_username,VAU_endTime,VAU_vpsEndTime,VAU_proDataName,VAU_vpsName,VAU_xufeiNum from '. OT_dbPref .'vpsApiUsers where VAU_ID='. $dataID);
			if (! $row = $dataexe->fetch()){ JS::AlertBackEnd('该记录不存在。'); }
			$apiID			= $row['VAU_apiID'];
			$endTime		= $row['VAU_endTime'];
			$vpsEndTime		= $row['VAU_vpsEndTime'];
			$userID			= $row['VAU_userID'];
			$username		= $row['VAU_username'];
			$proDataName	= $row['VAU_proDataName'];
			$vpsName		= $row['VAU_vpsName'];
			$xufeiNum		= $row['VAU_xufeiNum'];

			if (! strtotime($endTime)){
				JS::AlertBackEnd('到期时间获取异常（'. $endTime .'），请刷新页面后重新操作下。');
			}

			$endTime = IdcArea::NewEndTime($payMode, $endTime);
			$vpsEndTime = IdcArea::NewEndTime($payMode, $vpsEndTime);

			$alertStr2 = '';
			$userMoney = -9;
			$recomId = 0;
			if ($isUserPay == 1){
				if ($userPrice == 0){ JS::AlertBackEnd('从用户金额扣款，扣款金额不能为0。'); }
				if ($userID == 0){ JS::AlertBackEnd('该记录未指定用户，不能使用 从用户金额扣款 功能。'); }
				$urs = $DB->GetRow('select UE_recomId,UE_recomUser,UE_money from '. OT_dbPref .'users where UE_ID='. $userID);
				$recomId	= $urs['UE_recomId'];
				$recomUser	= $urs['UE_recomUser'];
				$userMoney	= floatval($urs['UE_money']);
				unset($urs);

				if ( OT::FloatCmp($userMoney, $userPrice) < 0 ){
					JS::AlertBackEnd('用户余额'. $userMoney .'元，扣款'. $userPrice .'元，余额不足，没法扣款。');
				}

				$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money-'. $userPrice,'UE_payMoney'=>'UE_payMoney+'. $userPrice),'UE_ID='. $userID);
					if (! $result){ JS::AlertBackEnd('用户余额扣款失败，请刷新页面重试下。'); }
				$alertStr2 .= '\n用户金额 '. $userMoney .' 元，扣款 '. $userPrice .' 元，剩余 '. OT::NumFormat($userMoney - $userPrice) .' 元';
			}else{
				if ($userID > 0){
					$urs = $DB->GetRow('select UE_recomId,UE_recomUser,UE_money from '. OT_dbPref .'users where UE_ID='. $userID);
					$recomId	= $urs['UE_recomId'];
					$recomUser	= $urs['UE_recomUser'];
					$userMoney	= floatval($urs['UE_money']);
					unset($urs);
				}
				/* $userPrice = 0; */
			}

			if ($apiID > 0){
				$retArr = AppIdcVps::Xufei($payMode,$userPrice,$userCost,$endTime,$dataID,array('timeObj'=>$timeObj,'apiObj'=>$apiObj));
				if (! $retArr['res']){
					$alertStr .= '\n上级API续费失败！'. $retArr['note'];
					if ($isUserPay == 1){
						$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money+'. $userPrice,'UE_payMoney'=>'UE_payMoney-'. $userPrice),'UE_ID='. $userID);
					}
					JS::AlertBackEnd($alertStr);
				}
				$alertStr .= '\n上级API续费成功！'. $retArr['note'];
			}else{
				$dataArr = array();
				$dataArr['VAU_payMode']		= $payMode;
				$dataArr['VAU_price']		= $userPrice;
				$dataArr['VAU_cost']		= $userCost;
				$dataArr['VAU_xufeiNum']	= 'VAU_xufeiNum+1';
				if ($timeObj == 1){ $dataArr['VAU_endTime'] = $endTime; }
				if ($apiObj == 1){ $dataArr['VAU_vpsEndTime'] = $vpsEndTime; }
				if (count($dataArr) == 0){ JS::AlertBackEnd('到期时间 和 API到期 至少打钩一个。'); }

				$result = $DB->UpdateParam('vpsApiUsers', $dataArr, 'VAU_ID='. $dataID);
					if (! $result){
						JS::AlertBackEnd('续费失败！'. $alertStr2);
					}else{
						$alertStr = '续费成功！';
					}
			}

			if ($isUserPay == 0){
				if ($userMoney != -9){ $userMoney += $userPrice; }
				$scoreArr = array();
				$scoreArr['MR_userID']		= $userID;
				$scoreArr['MR_username']	= $username;
				$scoreArr['MR_dataID']		= $dataID;
				$scoreArr['MR_dataName']	= $vpsName;
				$scoreArr['MR_type']		= 'suff';
				$scoreArr['MR_type2']		= '后台充值';
				$scoreArr['MR_money']		= $userPrice;
				$scoreArr['MR_remMoney']	= $userMoney;
				$scoreArr['MR_bank']		= '账户余额';
				$scoreArr['MR_note']		= '后台充值成功！充值金额：'. $userPrice .'元，备注：'. $moneyNote;
				$scoreArr['MR_adminID']		= $MB->mMbRow['MB_ID'];
				$scoreArr['MR_adminName']	= $MB->mMbRow['MB_realname'];
				$mrRes = AppMoneyRecord::AddData($scoreArr);
			}

			$userGain = $userPrice - $userCost;
			if ($userGain < 0){ $userGain = 0; }
			if ($userMoney != -9){ $userMoney -= $userPrice; }
			$scoreArr = array();
			$scoreArr['MR_userID']		= $userID;
			$scoreArr['MR_username']	= $username;
			$scoreArr['MR_dataID']		= $dataID;
			$scoreArr['MR_dataName']	= $vpsName;
			$scoreArr['MR_type']		= 'vpsApi';
			$scoreArr['MR_type2']		= '续费';
			$scoreArr['MR_money']		= $userPrice*(-1);
			$scoreArr['MR_remMoney']	= $userMoney;
			$scoreArr['MR_cost']		= $userCost;
			$scoreArr['MR_gain']		= $userGain;
			$scoreArr['MR_bank']		= '账户余额';
			$scoreArr['MR_note']		= '后台续费成功！产品：'. $proDataName .'；机器编码：'. $vpsName .'；续费期限：'. IdcInfo::PayTime($payMode) .'（'. TimeDate::Get('date',$endTime) .'到期）；价格：'. $userPrice .'元；';
			$scoreArr['MR_adminID']		= $MB->mMbRow['MB_ID'];
			$scoreArr['MR_adminName']	= $MB->mMbRow['MB_realname'];
			$mrRes = AppMoneyRecord::AddData($scoreArr);
				if ($mrRes){ $mrAlertStr=''; }else{ $mrAlertStr='\n财务信息记录失败（需要“财务基础包”插件支持）！'; }
			$alertStr .= $alertStr2 . $mrAlertStr;

			// 如有推荐人，推荐人推广佣金处理
			$vpsSysArr = Cache::PhpFile('vpsSys');
			if ($recomId > 0 && strpos($vpsSysArr['VS_commArea'],'|vpsApiXuAdmin|') !== false && $xufeiNum < $vpsSysArr['VS_vpsApiXuNum']){
				$urs = $DB->GetRow('select UE_makeMoney,UE_makingMoney from '. OT_dbPref .'users where UE_ID='. $recomId);
				$makeMoney	= floatval($urs['UE_makeMoney']);
				$makingMoney= floatval($urs['UE_makingMoney']);
				unset($urs);

				$proPrice	= abs($userPrice);
				$money = $proPrice * $vpsSysArr['VS_vpsApiXuRate'];
				if ($money > $vpsSysArr['VS_vpsApiXuMax']){ $money = $vpsSysArr['VS_vpsApiXuMax']; }
				$proArr = array(
					'GI_source'			=> '后台',
					'GI_userID'			=> $recomId,
					'GI_username'		=> $recomUser,
					'GI_proUserID'		=> $userID,
					'GI_proUsername'	=> $username,
					'GI_proType'		=> 'vpsApi',
					'GI_proID'			=> $dataID,
					'GI_proName'		=> $proDataName,
					'GI_proPrice'		=> $proPrice,
					'GI_vpsName'		=> $vpsName,
					'GI_endTime'		=> $endTime,
					'GI_mode'			=> '续费',
					'GI_rate'			=> $vpsSysArr['VS_vpsApiXuRate'],
					'GI_money'			=> $money,
					);
				$listArr = array(
					'GH_makingMoney'	=> $makingMoney + $money,
					'GH_makeMoney'		=> $makeMoney,
					);
				AppGain::AddItemData($proArr, $listArr);
			}
			break;
	
		// 调整价格/成本
		case 'price':
			$priceMode		= OT::PostStr('priceMode');
			$pricePrice		= OT::PostFloat('pricePrice');
			$priceCost		= OT::PostFloat('priceCost');

			$dataArr = array();
			$dataArr['VAU_payMode']		= $priceMode;
			$dataArr['VAU_price']		= $pricePrice;
			$dataArr['VAU_cost']		= $priceCost;

			$result = $DB->UpdateParam('vpsApiUsers', $dataArr, 'VAU_ID='. $dataID);
			if ($result){
				$alertRes='成功';
			}else{
				$alertRes='失败';
			}
			$alertStr = '调整价格/成本'. $alertRes .'！';
			break;

		// 调整时间
		case 'setTime':
			$setTime		= OT::PostStr('setTime');
			$setEndTime		= OT::PostStr('setEndTime');
			$setNote		= OT::PostStr('setNote');
			$isUserPay		= OT::PostInt('isUserPay');
			$userPrice		= OT::PostFloat('userPrice');

			if (strlen($setTime)==0 && strlen($setEndTime)==0){
				JS::AlertBackEnd('手工指定开通时间和到期时间不能都为空');
			}

			$dataexe = $DB->query('select VAU_userID,VAU_username,VAU_time,VAU_endTime,VAU_proDataName,VAU_vpsName from '. OT_dbPref .'vpsApiUsers where VAU_ID='. $dataID);
			if (! $row = $dataexe->fetch()){ JS::AlertBackEnd('该记录不存在。'); }
			$userID			= $row['VAU_userID'];
			$username		= $row['VAU_username'];
			$VAU_time		= $row['VAU_time'];
			$VAU_endTime	= $row['VAU_endTime'];
			$proDataName	= $row['VAU_proDataName'];
			$vpsName		= $row['VAU_vpsName'];

			$timeAlertStr = '';
			$dataArr = array();
			if (strlen($setTime)>0){
				if (! strtotime($setTime)){ JS::AlertBackEnd('开通时间 日期格式错误'); }
				$dataArr['VAU_time'] = $setTime;
				$timeAlertStr .= '开通时间（'. $VAU_time .'）调整为：'. $setTime .';';
			}
			if (strlen($setEndTime)>0){
				if (! strtotime($setEndTime)){ JS::AlertBackEnd('到期时间 日期格式错误'); }
				$dataArr['VAU_endTime'] = $setEndTime;
				$timeAlertStr .= '到期时间（'. $VAU_endTime .'）调整为：'. $setEndTime .';';
			}
			if (strlen($setTime)>0 && strlen($setEndTime)>0 && strtotime($setTime)>strtotime($setEndTime)){
				JS::AlertBackEnd('开通时间 不能大于 到期时间');
			}

			$alertStr2 = '';
			$userMoney = -9;
			if ($isUserPay == 1){
				if ($userPrice == 0){ JS::AlertBackEnd('从用户金额扣款，扣款金额不能为0。'); }
				if ($userID == 0){ JS::AlertBackEnd('该记录未指定用户，不能使用 从用户金额扣款 功能。'); }
				$userMoney = floatval($DB->GetOne('select UE_money from '. OT_dbPref .'users where UE_ID='. $userID));
					if ( OT::FloatCmp($userMoney, $userPrice) < 0 ){
						JS::AlertBackEnd('用户余额'. $userMoney .'元，扣款'. $userPrice .'元，余额不足，没法扣款。');
					}
				$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money-'. $userPrice,'UE_payMoney'=>'UE_payMoney+'. $userPrice),'UE_ID='. $userID);
					if (! $result){
						JS::AlertBackEnd('用户余额扣款失败，请刷新页面重试下。');
					}
				$alertStr2 .= '\n用户金额 '. $userMoney .' 元，扣款 '. $userPrice .' 元，剩余 '. OT::NumFormat($userMoney - $userPrice) .' 元';
			}else{
				$userPrice = 0;
			}

			$result = $DB->UpdateParam('vpsApiUsers', $dataArr, 'VAU_ID='. $dataID);
			if ($result){
				$alertRes='成功';
				$scoreArr = array();
				$scoreArr['MR_userID']		= $userID;
				$scoreArr['MR_username']	= $username;
				$scoreArr['MR_dataID']		= $dataID;
				$scoreArr['MR_dataName']	= $vpsName;
				$scoreArr['MR_type']		= 'vpsApi';
				$scoreArr['MR_type2']		= '调整时间';
				$scoreArr['MR_money']		= $userPrice*(-1);
				$scoreArr['MR_remMoney']	= $userMoney - $userPrice;
				$scoreArr['MR_bank']		= '账户余额';
				$scoreArr['MR_note']		= '调整时间成功！产品：'. $proDataName .'；机器编码：'. $vpsName .'；'. $timeAlertStr .'调整价格：'. $userPrice .'元；说明原因：'. $setNote .'；';
				$scoreArr['MR_adminID']		= $MB->mMbRow['MB_ID'];
				$scoreArr['MR_adminName']	= $MB->mMbRow['MB_realname'];
				$mrRes = AppMoneyRecord::AddData($scoreArr);
					if ($mrRes){ $mrAlertStr=''; }else{ $mrAlertStr='\n财务信息记录失败（需要“财务基础包”插件支持）！'; }
				$alertStr2 .= $mrAlertStr;
			}else{
				$alertRes='失败';
			}
			$alertStr = '调整时间'. $alertRes .'！'. $alertStr2;
			break;
	
		// 调整API到期时间
		case 'setApiTime':
			$setApiTime		= OT::PostStr('setApiTime');

			if (strlen($setApiTime)==0){
				JS::AlertBackEnd('API到期时间不能都为空');
			}

			$dataArr = array();
			$dataArr['VAU_vpsEndTime'] = $setApiTime;

			$result = $DB->UpdateParam('vpsApiUsers', $dataArr, 'VAU_ID='. $dataID);
			if ($result){
				$alertRes='成功';
			}else{
				$alertRes='失败';
			}
			$alertStr = '调整API时间'. $alertRes .'！';
			break;
	
		// 升级
		case 'update':
			$newProDataID	= OT::PostInt('proDataID');
				if ($newProDataID <= 0){ JS::AlertBackEnd('升级产品ID错误.'); }
			$isUserPay		= OT::PostInt('isUserPay');
			$userPrice		= OT::PostFloat('userPrice');
			$newPrice		= OT::PostFloat('newPrice');
			$newCost		= OT::PostFloat('newCost');
			$moneyNote		= OT::PostStr('moneyNote');
				// if ($userPrice == 0){ JS::AlertBackEnd('扣款金额不能为0。'); }

			$dataexe = $DB->query('select VAU_apiID,VAU_userID,VAU_username,VAU_proDataName,VAU_payMode,VAU_vpsName,VAU_isNewPrice from '. OT_dbPref .'vpsApiUsers where VAU_ID='. $dataID);
			if (! $row = $dataexe->fetch()){ JS::AlertBackEnd('该记录不存在。'); }
			$apiID			= $row['VAU_apiID'];
			$userID			= $row['VAU_userID'];
			$username		= $row['VAU_username'];
			$proDataName	= $row['VAU_proDataName'];
			$payMode		= $row['VAU_payMode'];
			$vpsName		= $row['VAU_vpsName'];
			$isNewPrice		= $row['VAU_isNewPrice'];

			/*
			$fieldArr = IdcInfo::PayModeField($payMode,'VAD_');

			$newProexe = $DB->query('select VAD_theme,'. $fieldArr['price'] .','. $fieldArr['cost'] .' from '. OT_dbPref .'vpsApiData where VAD_ID='. $newProDataID);
				if (! $rs = $newProexe->fetch()){ JS::AlertBackEnd('该升级产品记录不存在。'); }
			$newProDataName		= $rs['VAD_theme'];
			//$newProPriceMonth	= $rs['VAD_priceMonth'];
			//$price			= $rs[$fieldArr['price']];
			//$cost				= $rs[$fieldArr['cost']];
			*/
			$newProDataName = $DB->GetOne('select VAD_theme from '. OT_dbPref .'vpsApiData where VAD_ID='. $newProDataID);

			$alertStr2 = '';
			$userMoney = -9;
			if ($isUserPay == 1){
				if ($userPrice == 0){ JS::AlertBackEnd('从用户金额扣款，扣款金额不能为0。'); }
				if ($userID == 0){ JS::AlertBackEnd('该记录未指定用户，不能使用 从用户金额扣款 功能。'); }
				$userMoney = floatval($DB->GetOne('select UE_money from '. OT_dbPref .'users where UE_ID='. $userID));
					if ( OT::FloatCmp($userMoney, $userPrice) < 0 ){
						JS::AlertBackEnd('用户余额'. $userMoney .'元，扣款'. $userPrice .'元，余额不足，没法扣款。');
					}
				$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money-'. $userPrice,'UE_payMoney'=>'UE_payMoney+'. $userPrice),'UE_ID='. $userID);
					if (! $result){ JS::AlertBackEnd('用户余额扣款失败，请刷新页面重试下。'); }
				$alertStr2 .= '\n用户金额 '. $userMoney .' 元，扣款 '. $userPrice .' 元，剩余 '. OT::NumFormat($userMoney - $userPrice) .' 元';
			}else{
				if ($userID > 0){ $userMoney = floatval($DB->GetOne('select UE_money from '. OT_dbPref .'users where UE_ID='. $userID)); }
				/* $userPrice = 0; */
			}

			if ($apiID > 0){
				$retArr = AppIdcVps::Update($newProDataID, $newPrice, $newCost, $dataID);
				if (! $retArr['res']){
					$alertStr .= '\n上级API升级失败！'. $retArr['note'];
					if ($isUserPay == 1){
						$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money+'. $userPrice,'UE_payMoney'=>'UE_payMoney-'. $userPrice),'UE_ID='. $userID);
					}
					JS::AlertBackEnd($alertStr);
				}
			}else{
				$dataArr = array(
					'VAU_isNewPrice'	=> 0,
					'VAU_price'			=> $newPrice,
					'VAU_cost'			=> $newCost,
					'VAU_proDataID'		=> $newProDataID,
					'VAU_proDataName'	=> $newProDataName
					);
				$result = $DB->UpdateParam('vpsApiUsers', $dataArr, 'VAU_ID='. $dataID);
					if (! $result){
						JS::AlertBackEnd('升级失败！'. $alertStr2);
					}
			}

			if ($isUserPay == 0){
				if ($userMoney != -9){ $userMoney += $userPrice; }
				$scoreArr = array();
				$scoreArr['MR_userID']		= $userID;
				$scoreArr['MR_username']	= $username;
				$scoreArr['MR_dataID']		= $dataID;
				$scoreArr['MR_dataName']	= $vpsName;
				$scoreArr['MR_type']		= 'suff';
				$scoreArr['MR_type2']		= '后台充值';
				$scoreArr['MR_money']		= $userPrice;
				$scoreArr['MR_remMoney']	= $userMoney;
				$scoreArr['MR_bank']		= '账户余额';
				$scoreArr['MR_note']		= '后台充值成功！充值金额：'. $userPrice .'元，备注：'. $moneyNote;
				$scoreArr['MR_adminID']		= $MB->mMbRow['MB_ID'];
				$scoreArr['MR_adminName']	= $MB->mMbRow['MB_realname'];
				$mrRes = AppMoneyRecord::AddData($scoreArr);
			}

			// $userGain = $userPrice - $newCost;
			// if ($userGain < 0){ $userGain = 0; }
			if ($userMoney != -9){ $userMoney -= $userPrice; }
			$scoreArr = array();
			$scoreArr['MR_userID']		= $userID;
			$scoreArr['MR_username']	= $username;
			$scoreArr['MR_dataID']		= $dataID;
			$scoreArr['MR_dataName']	= $vpsName;
			$scoreArr['MR_type']		= 'vpsApi';
			$scoreArr['MR_type2']		= '升级';
			$scoreArr['MR_money']		= $userPrice*(-1);
			$scoreArr['MR_remMoney']	= $userMoney;
			// $scoreArr['MR_cost']		= $newCost;
			// $scoreArr['MR_gain']		= $userGain;
			$scoreArr['MR_bank']		= '账户余额';
			$scoreArr['MR_note']		= '后台升级产品成功！旧产品：'. $proDataName .'，新产品：'. $newProDataName .'；机器编码：'. $vpsName .'；价格：'. $userPrice .'元；';
			$scoreArr['MR_adminID']		= $MB->mMbRow['MB_ID'];
			$scoreArr['MR_adminName']	= $MB->mMbRow['MB_realname'];
			$mrRes = AppMoneyRecord::AddData($scoreArr);
				if ($mrRes){ $mrAlertStr=''; }else{ $mrAlertStr='\n财务信息记录失败（需要“财务基础包”插件支持）！'; }

			$alertStr = '升级成功！'. $alertStr2 . $mrAlertStr;
			if ($isNewPrice == 1){ $alertStr .= '\n为防止续费价格错误，【单独设置续费价格】项自动关闭，请重新设置\n'; }
			break;

		// 退款
		case 'back':
			$backMoney		= OT::PostFloat('backMoney');
			$backNote		= OT::PostStr('backNote');

			$dataexe = $DB->query('select VAU_userID,VAU_username,VAU_proDataName,VAU_vpsName,VAU_cost from '. OT_dbPref .'vpsApiUsers where VAU_ID='. $dataID);
			if (! $row = $dataexe->fetch()){ JS::AlertBackEnd('该记录不存在。'); }
			$userID			= $row['VAU_userID'];
			$username		= $row['VAU_username'];
			$proDataName	= $row['VAU_proDataName'];
			$vpsName		= $row['VAU_vpsName'];
			$cost			= $row['VAU_cost'];

			$alertStr2 = '';
			$userMoney = -9;
			if ($backMoney > 0){
				if ($userID == 0){ JS::AlertBackEnd('该记录未指定用户，退款金额只能填0元。'); }
				$userMoney = floatval($DB->GetOne('select UE_money from '. OT_dbPref .'users where UE_ID='. $userID));
				$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money+'. $backMoney,'UE_payMoney'=>'UE_payMoney-'. $backMoney),'UE_ID='. $userID);
					if (! $result){
						JS::AlertBackEnd('用户退款处理失败，请刷新页面重试下。');
					}
				$alertStr2 .= '\n用户原金额 '. $userMoney .' 元，退款 '. $backMoney .' 元，现金额 '. OT::NumFormat($userMoney + $backMoney) .' 元';
			}

			$dataArr = array(
				'VAU_endTime'	=> TimeDate::Get(),
				'VAU_state'		=> 9
				);
			$result = $DB->UpdateParam('vpsApiUsers', $dataArr, 'VAU_ID='. $dataID);
			if ($result){
				$userGain = $cost - $backMoney;
				if ($userGain > 0){ $userGain = 0; }
				$alertRes='成功';
				$scoreArr = array();
				$scoreArr['MR_userID']		= $userID;
				$scoreArr['MR_username']	= $username;
				$scoreArr['MR_dataID']		= $dataID;
				$scoreArr['MR_dataName']	= $vpsName;
				$scoreArr['MR_type']		= 'vpsApi';
				$scoreArr['MR_type2']		= '退款';
				$scoreArr['MR_money']		= $backMoney;
				$scoreArr['MR_remMoney']	= $userMoney + $backMoney;
				$scoreArr['MR_cost']		= $cost;
				$scoreArr['MR_gain']		= $userGain;
				$scoreArr['MR_bank']		= '账户余额';
				$scoreArr['MR_note']		= '后台退款成功！产品：'. $proDataName .'，机器编码：'. $vpsName .'；退款：'. $backMoney .'元；退款原因：'. $backNote .'';
				$scoreArr['MR_adminID']		= $MB->mMbRow['MB_ID'];
				$scoreArr['MR_adminName']	= $MB->mMbRow['MB_realname'];
				$mrRes = AppMoneyRecord::AddData($scoreArr);
					if ($mrRes){ $mrAlertStr=''; }else{ $mrAlertStr='\n财务信息记录失败（需要“财务基础包”插件支持）！'; }
				$alertStr2 .= $mrAlertStr;
			}else{
				$alertRes='失败';
			}

			$alertStr = '退款'. $alertRes .'！'. $alertStr2;
			break;
	
		// 删除
		case 'del':
			$delMode	= OT::PostInt('delMode');
			if ($delMode != 1){
				JS::AlertBackEnd('获取不到删除确定参数，请刷新页面重试下。');
			}

			$row = $DB->GetRow('select VAU_state,VAU_endTime from '. OT_dbPref .'vpsApiUsers where VAU_ID='. $dataID);
				if (! $row){
					JS::AlertBackEnd('该记录已不存在，请刷新页面再操作下试试。'. $row['VAU_state']);
				}
				$diffDay = TimeDate::Diff('d', $row['VAU_endTime'], TimeDate::Get());
				if ($diffDay >= 7){
					// 到期时间超过天数，无需停止状态均可删除
				}else{
					if (! in_array($row['VAU_state'],array(0,6,9)) ){
						JS::AlertBackEnd('当前状态['. $row['VAU_state'] .']不允许删除，只有过期超过7天、开通失败、停止或已退款状态才能删除');
					}
				}

			$retRes = AdmIdc::AddDelUsers('vpsApi', $dataID);
				if (! $retRes){
					JS::AlertBackEnd('记录写入回收站失败。');
				}

			$result = $DB->Delete('vpsApiUsers','VAU_ID='. $dataID);
				if ($result){
					$DB->Delete('vpsApiTixing','VAT_dataID='. $dataID);
					$alertRes='成功';
				}else{
					$alertRes='失败';
				}

			$alertStr = '删除'. $alertRes .'！';
			JS::AlertClose($alertStr);
			break;

		default :
			JS::AlertBackEnd('目的不明确.');
			break;
	}

	JS::AlertHref($alertStr,$backURL);
}



// 同步
function sync(){
	global $DB;

	@ini_set('max_execution_time', 0);
	@set_time_limit(0); 

	$mudi2	= OT::GetStr('mudi2');
	$theme	= OT::GetStr('theme');
	$dataID	= OT::GetInt('dataID');
		if ( $dataID <= 0 ){ JS::AlertEnd('ID值错误.'); }
		if (! in_array($mudi2,array('api','endTime')) ){ JS::AlertEnd('目的不明确.'); }

	if ($mudi2 == 'endTime'){
		$result = $DB->query('update '. OT_dbPref .'vpsApiUsers SET VAU_endTime=VAU_vpsEndTime where VAU_ID='. $dataID);
		$retArr = array('res'=>$result, 'note'=>'');
	}else{
		$retArr = AppIdcVps::Sync($dataID,$mudi2);
	}
	if ($retArr['res']){
		$alertStr = '';
		if (isset($retArr['ori'])){ $alertStr = '\n反馈原内容：'. $retArr['ori'] .''; }
		die('<script language="javascript" type="text/javascript">alert("同步更新成功\n'. $retArr['note'] . $alertStr .'");parent.document.location.reload();</script>');
	}else{
		JS::AlertEnd('同步更新失败，原因：'. $retArr['note'] .'.');
	}
}


// 云服务器导入
function ImportDeal(){
	global $DB,$MB;

	$backURL		= OT::PostStr('backURL');
	$dataType		= OT::PostStr('dataType');
	$dataTypeCN		= OT::PostStr('dataTypeCN');

	$apiID			= OT::PostInt('apiID');
	$classID		= OT::PostInt('classID');
	$prefName		= OT::PostStr('prefName');
	$useNum			= OT::PostInt('useNum');
	$numLen			= OT::PostInt('numLen');

	$proDataID		= OT::PostInt('proDataID');
	$proDataName	= $DB->GetOne('select VAD_theme from '. OT_dbPref .'vpsApiData where VAD_ID='. $proDataID);
	$username		= OT::PostStr('username');
	$vpsName		= OT::PostStr('vpsName');
	$isAutoName		= OT::PostInt('isAutoName');
	$vpsPwd			= OT::PostStr('vpsPwd');
	$vpsCpUrl		= OT::PostStr('vpsCpUrl');
	$orderId		= OT::PostStr('orderId');
	$workSign		= OT::PostStr('workSign');
	$workId			= OT::PostStr('workId');
	$ip				= OT::PostStr('ip');
	$spaceSize		= OT::PostInt('spaceSize');
	$time			= OT::PostStr('time');
	$endTime		= OT::PostStr('endTime');
	$vpsEndTime		= OT::PostStr('vpsEndTime');
	$system			= OT::PostStr('system');
	$payMode		= OT::PostStr('payMode');
	$price			= OT::PostFloat('price');
	$cost			= OT::PostFloat('cost');
	$note			= OT::PostStr('note');
	$adminNote		= OT::PostStr('adminNote');

	if ($proDataID==0 || strlen($vpsName)==0 || (strlen($workId)==0 && strlen($vpsName)==0) || strlen($ip)==0 || strlen($endTime)==0 || strlen($vpsEndTime)==0){
		JS::AlertBackEnd('表单内容接收不全');
	}

	$userID = 0;
	if (strlen($username) > 0){ $userID = $DB->GetOne('select UE_ID from '. OT_dbPref .'users where UE_username='. $DB->ForStr($username)); }

	$alertStr = '';
	$VC_useNum = 0;
	$chkexe = $DB->QueryParam('select VAU_ID from '. OT_dbPref .'vpsApiUsers where VAU_vpsName=? limit 1',array($vpsName));
	if ($chkexe->fetch()){
		if ($isAutoName == 1){
			$vpsNameArr = IdcArea::GetNewVpsName('vpsApi',$classID);
			$VC_useNum = $vpsNameArr['useNum'];
			$vpsName = $vpsNameArr['vpsName'];
			$alertStr .= '\n机器编码已被占用，自动重名为 '. $vpsName;
		}else{
			JS::AlertBackEnd('机器编码已被占用，请更换个');
		}
	}
	unset($chkexe);

	$dataArr = array();
	$dataArr['VAU_time']			= $time;
	$dataArr['VAU_endTime']			= $endTime;
	$dataArr['VAU_apiID']			= $apiID;
	$dataArr['VAU_proDataID']		= $proDataID;
	$dataArr['VAU_proDataName']		= $proDataName;
	$dataArr['VAU_userID']			= $userID;
	$dataArr['VAU_username']		= $username;
	$dataArr['VAU_orderId']			= $orderId;
	$dataArr['VAU_workId']			= $workId;
	$dataArr['VAU_workSign']		= $workSign;
	$dataArr['VAU_vpsName']			= $vpsName;
	$dataArr['VAU_vpsPwd']			= Encrypt::SyEnDe('en',$vpsPwd);
	$dataArr['VAU_vpsCpUrl']		= $vpsCpUrl;
	$dataArr['VAU_vpsEndTime']		= $vpsEndTime;
	$dataArr['VAU_ipStr']			= $ip;
	$dataArr['VAU_payMode']			= $payMode;
	$dataArr['VAU_price']			= $price;
	$dataArr['VAU_cost']			= $cost;
	$dataArr['VAU_system']			= $system;
	$dataArr['VAU_spaceSize']		= $spaceSize;
	$dataArr['VAU_note']			= $note;
	$dataArr['VAU_isUserPay']		= in_array($payMode,array('24hour','48hour')) ? 0 : 1;
	$dataArr['VAU_adminNote']		= $adminNote;

	$dataArr['VAU_state']			= 10;
	$dataArr['VAU_adminID']			= $MB->mUserID;
	$dataArr['VAU_adminName']		= $MB->mMbRow['MB_realname'];

	$judRes = $DB->InsertParam('vpsApiUsers', $dataArr);
		if ($judRes){
			if ($VC_useNum > 0){ $DB->UpdateParam('vpsClass',array('VC_useNum'=>$VC_useNum),'VC_ID='. $classID); }
			JS::AlertHref('导入成功！'. $alertStr, $backURL);
		}else{
			JS::AlertBackEnd('导入失败！');
		}

}


// 读取导入信息
function LoadInfo(){
	global $DB,$MB;

	$apiID		= OT::GetInt('apiID');
	$companyID	= OT::GetInt('companyID');
	$pcountry	= OT::GetStr('pcountry');
	$ptype		= OT::GetStr('ptype');
	$vpsName	= OT::GetStr('vpsName');
	$orderId	= OT::GetStr('orderId');
	$workSign	= OT::GetStr('workSign');
	$workId		= OT::GetStr('workId');

	$comRow = $DB->GetRow('select VC_apiDomain,VC_apiUsername,VC_apiUserPwd from '. OT_dbPref .'vpsCompany where VC_ID='. $companyID);

	if ($apiID == 1 || $apiID == 6){	// 1星外 6网钛IDC
		$chkexe = $DB->query('select VAU_ID from '. OT_dbPref .'vpsApiUsers where VAU_vpsName='. $DB->ForStr($vpsName));
		if ($row = $chkexe->fetch()){
			JS::AlertEnd('该机器编码已存在，不能添加.');
		}
		unset($chkexe);

		$rndStr = OT::RndChar(16);
		$dataArr = array(
			'apiDomain'		=> $comRow['VC_apiDomain'],
			'apiUsername'	=> $comRow['VC_apiUsername'],
			'apiUserPwd'	=> ApiXingwai::PwdMd5(Encrypt::SyEnDe('de',$comRow['VC_apiUserPwd'])),
			'vpsName'		=> $vpsName,
			'note'			=> $rndStr,
			);
		if ($apiID == 6){
			$dataArr['apiUserPwd'] = Encrypt::SyEnDe('de',$comRow['VC_apiUserPwd']);
			$resArr = ApiIdccms::VpsSync($dataArr, 'idcServ');
			if (! $resArr['res']){
				JS::AlertEnd('同步获取信息失败（'. $resArr['note'] .'）');
			}
			echo('
			$id("time").value = "'. $resArr['startTime'] .'";
			$id("endTime").value = "'. $resArr['endTime'] .'";
			$id("vpsEndTime").value = "'. $resArr['endTime'] .'";
			$id("ip").value = "'. str_replace(array('|'), array('\r\n'), $resArr['ip']) .'";
			$id("vpsPwd").value = "'. $resArr['vpsPwd'] .'";
			');
		}else{
			$resArr = ApiXingwai::VpsSync($dataArr);
			if (! $resArr['res']){
				JS::AlertEnd('同步获取信息失败（'. $resArr['note'] .'）');
			}
			echo('
			$id("endTime").value = "'. $resArr['endtime'] .'";
			$id("vpsEndTime").value = "'. $resArr['endtime'] .'";
			$id("ip").value = "'. str_replace(array('|'), array('\r\n'), $resArr['ip']) .'";
			$id("vpsPwd").value = "'. $resArr['vpspassword'] .'";
			$id("vpsCpUrl").value = "'. $resArr['cpurl'] .'";
			');
		}

	}elseif ($apiID == 2){	// 景安
		ApiJingan::$accessId	= $comRow['VC_apiUsername'];
		ApiJingan::$accessKey	= Encrypt::SyEnDe('de',$comRow['VC_apiUserPwd']);
		ApiJingan::$urlMode		= $pcountry;
/*		$chkexe = $DB->query('select VAU_ID from '. OT_dbPref .'vpsApiUsers where VAU_orderId='. $DB->ForStr($orderId));
		if ($row = $chkexe->fetch()){
			JS::AlertEnd('该订单编号已存在，不能添加.');
		}
		unset($chkexe);

		$dataArr = array(
			'ptype'		=> $ptype,
			'orderId'	=> $orderId,
			);
		$resArr = ApiJingan::VpsWorkId($dataArr);
		if (! $resArr['res']){
			JS::AlertEnd('通过订单号获取业务编号失败（'. $resArr['note'] .'）');
		}
		$workId = $resArr['info']['bid'];
*/
		$chkexe = $DB->query('select VAU_ID from '. OT_dbPref .'vpsApiUsers where VAU_workId='. $DB->ForStr($workId));
		if ($row = $chkexe->fetch()){
			JS::AlertEnd('该业务编号已存在，不能添加.');
		}
		unset($chkexe);
		$dataArr = array(
			'ptype'		=> $ptype,
			'workId'	=> $workId,
			);
		$resArr = ApiJingan::VpsSync2($dataArr);
		if (! $resArr['res']){
			JS::AlertEnd('同步获取信息失败（'. $resArr['note'] .'）');
		}
//		$id("workId").value = "'. $workId .'";
		echo('
		$id("workSign").value = "'. $resArr['info']['Extir']['ip'] .'";
		$id("time").value = "'. $resArr['info']['Extir']['createDate'] .'";
		$id("endTime").value = "'. $resArr['info']['Extir']['overDate'] .'";
		$id("vpsEndTime").value = "'. $resArr['info']['Extir']['overDate'] .'";
		$id("ip").value = "'. AppJingan::GetIpList($resArr) .'";
		$id("spaceSize").value = "'. $resArr['info']['config']['harDisk'] .'";
		$id("payMode").value = "'. ($resArr['info']['Extir']['status']==1?ApiJingan::PayModeMonthStr($resArr['info']['Extir']['serviceTime']):'48hour') .'";
		CheckPayMode();
		');
	
	}else{
		JS::AlertEnd('API接口不对');
	}

}


// 导入VPS信息
function GetList(){
	global $DB,$MB;

	$apiID		= 2;	// OT::GetInt('apiID')

	$comRow = $DB->GetRow('select VC_apiDomain,VC_apiUsername,VC_apiUserPwd from '. OT_dbPref .'vpsCompany where VC_apiID='. $apiID);

	if ($apiID == 2){	// 景安
		echo('<title>景安快云比对核验</title>');
		ApiJingan::$accessId	= $comRow['VC_apiUsername'];
		ApiJingan::$accessKey	= Encrypt::SyEnDe('de',$comRow['VC_apiUserPwd']);

		$resArr = ApiJingan::GetVpsList();
		// print_r($resArr);die();
		if (! $resArr['res']){
			// JS::AlertEnd('获取快云vps所有业务编号失败（'. $resArr['note'] .'）');
			die('获取快云vps所有业务编号失败（'. $resArr['note'] .'）');
		}
		if (strlen($resArr['info']) == 0){
			// JS::AlertEnd('获取快云vps所有业务编号数据为空');
			die('获取快云vps所有业务编号数据为空');
		}
		$wordIdArr = explode(',',$resArr['info']);

		$endTime = TimeDate::Get('',strtotime('-6 day'));
		echo('<div>景安平台 快云VPS 共 '. count($wordIdArr) .' 台</div>');
		echo('<div>网钛IDC平台 快云VPS 共 '. $DB->GetOne('select count(VAU_ID) from '. OT_dbPref .'vpsApiUsers where VAU_apiID=2 and VAU_endTime>='. $DB->ForTime($endTime)) .' 台</div>');

		$vpsexe = $DB->query('select VAU_workId,VAU_vpsName,VAU_proDataName,VAU_endTime,VAU_ipStr,VAU_state from '. OT_dbPref .'vpsApiUsers where VAU_apiID=2 and VAU_endTime>='. $DB->ForTime($endTime));
		while ($row = $vpsexe->fetch()){
			if (strlen($row['VAU_workId']) < 3){
				echo('<div>'. $row['VAU_vpsName'] .'&ensp;&ensp;&ensp;&ensp;'. $row['VAU_ipStr'] .'&ensp;&ensp;&ensp;&ensp;'. $row['VAU_proDataName'] .'&ensp;&ensp;&ensp;&ensp;'. IdcInfo::State($row['VAU_state']) .'&ensp;&ensp;&ensp;&ensp;业务编号为空，无法判断</div>');
			}else{
				if (in_array($row['VAU_workId'],$wordIdArr)){
					$wordIdArr = array_diff($wordIdArr, array($row['VAU_workId']));
				}else{
					echo('<div>'. $row['VAU_vpsName'] .'&ensp;&ensp;&ensp;&ensp;'. $row['VAU_ipStr'] .'&ensp;&ensp;&ensp;&ensp;'. $row['VAU_proDataName'] .'&ensp;&ensp;&ensp;&ensp;'. IdcInfo::State($row['VAU_state']) .'，'. TimeDate::DiffDayCN($row['VAU_endTime'],'剩','<span style="color:red;">过期</span>') .'&ensp;&ensp;&ensp;&ensp;不在景安平台上</div>');
				}
			}
		}
		unset($vpsexe);

		if (count($wordIdArr) > 0){
			foreach ($wordIdArr as $val){
				echo('<div>业务编号 '. $val .' 不在网钛IDC平台上</div>');
			}
		}
	
	}else{
		JS::AlertEnd('API接口（'. $apiID .'）不对');
	}

}


// 用测试码开通
function UseTestCode(){
	global $DB,$MB;

	$dataID		= OT::GetInt('dataID');

	$chkexe = $DB->query('select VAU_ID,VAU_proDataID,VAU_orderId,VAU_system,VAU_endTime,VAU_state from '. OT_dbPref .'vpsApiUsers where VAU_ID='. $dataID);
	if (! $ru = $chkexe->fetch()){
		JS::AlertEnd('该云服务器不存在.');
	}
	if ($ru['VAU_state'] != 3){ JS::AlertEnd('该云服务器不是待开通状态['. $ru['VAU_state'] .'].'); }
	$orderId	= $ru['VAU_orderId'];
	$endTime	= $ru['VAU_endTime'];

	$proRow = $DB->GetRow('select VAD_typeID,VAD_comProID,VAD_comServID from '. OT_dbPref .'vpsApiData where VAD_ID='. $ru['VAU_proDataID']);

	$VT_companyID = $DB->GetOne('select VT_companyID from '. OT_dbPref .'vpsType where VT_ID='. $proRow['VAD_typeID'] .'');

	$comRow = $DB->GetRow('select VC_apiID,VC_apiDomain,VC_apiUsername,VC_apiUserPwd from '. OT_dbPref .'vpsCompany where VC_ID='. $VT_companyID .'');

	if ($comRow['VC_apiID'] == 1){	// 星外
	
	}elseif ($comRow['VC_apiID'] == 2){	// 景安
		ApiJingan::$accessId	= $comRow['VC_apiUsername'];
		ApiJingan::$accessKey	= Encrypt::SyEnDe('de',$comRow['VC_apiUserPwd']);
		for ($i=0; $i<10; $i++){
			$crs = $DB->GetRow('select JC_ID,JC_content from '. OT_dbPref .'jinganCode where JC_state=0 limit 1');
				if (! $crs){
					JS::AlertEnd('景安测试码已用完，请重新录入一批测试码（IDC设置-接口设置 [景安测试码管理]），再做该操作.');
				}
			$dataArr = array(
				'ptype'		=> 'vps',
				'orderId'	=> $orderId,
				'sysMode'	=> ApiJingan::VpsSysModeNum($ru['VAU_system']),
				'testCode'	=> $crs['JC_content'],
				'mail'		=> '',
				);
			$resArr = ApiJingan::UseTestCode($dataArr);
				if ($resArr['res']){
					$DB->UpdateParam('jinganCode', array('JC_state' => 1), 'JC_ID='. $crs['JC_ID']);
					break;
				}else{
					$DB->UpdateParam('jinganCode', array('JC_state' => 2), 'JC_ID='. $crs['JC_ID']);
				}
		}
		if (! $resArr['res']){
			JS::AlertEnd('用测试码开通失败（'. $resArr['note'] .'）');
		}else{
			if (! strtotime($endTime)){
				$endTime = $resArr['info']['overDate'];
			// }elseif (TimeDate::Diff('d',$endTime,$resArr['info']['overDate']) < 0){
			//	$endTime = $resArr['info']['overDate'];
			}
			$newArr = array();
			$newArr['VAU_state']		= 12;
			$newArr['VAU_apiID']		= $comRow['VC_apiID'];
			$newArr['VAU_workId']		= $resArr['info']['bid'];
			$newArr['VAU_workSign']		= $resArr['info']['ip'];
			$newArr['VAU_vpsEndTime']	= $resArr['info']['overDate'];
			$newArr['VAU_vpsUser']		= $resArr['info']['user'];
			$newArr['VAU_vpsPwd']		= Encrypt::SyEnDe('en',$resArr['info']['pwd']);
			$newArr['VAU_vpsPort']		= $resArr['info']['remoteport'];
			$newArr['VAU_ipStr']		= $resArr['info']['ip'];
			$newArr['VAU_endTime']		= $endTime;
			$retRes = $DB->UpdateParam('vpsApiUsers',$newArr,'VAU_ID='. $dataID);
				if ($retRes){
					echo('alert("用测试码开通成功，用户可以使用了。");document.location.reload();');
				}else{
					JS::AlertEnd('用测试码开通了，但更新记录失败。');
				}
		}
	
	}else{
		JS::AlertEnd('API接口不对');
	}

}



// 检查待开通机器的开通状态
function CheckKaitong(){
	global $DB,$MB;

	$dataID		= OT::GetInt('dataID');

	$chkexe = $DB->query('select VAU_ID,VAU_proDataID,VAU_orderId,VAU_workId,VAU_endTime,VAU_state from '. OT_dbPref .'vpsApiUsers where VAU_ID='. $dataID);
	if (! $ru = $chkexe->fetch()){
		JS::AlertEnd('该云服务器不存在.');
	}
	if ($ru['VAU_state'] != 3){ JS::AlertEnd('该云服务器不是待开通状态['. $ru['VAU_state'] .'].'); }
	$orderId	= $ru['VAU_orderId'];
	$workId		= $ru['VAU_workId'];
	$endTime	= $ru['VAU_endTime'];

	$proRow = $DB->GetRow('select VAD_typeID,VAD_ptype,VAD_pname,VAD_comProID,VAD_comServID from '. OT_dbPref .'vpsApiData where VAD_ID='. $ru['VAU_proDataID']);
	$ptype		= $proRow['VAD_ptype'];

	$VT_companyID = $DB->GetOne('select VT_companyID from '. OT_dbPref .'vpsType where VT_ID='. $proRow['VAD_typeID'] .'');

	$comRow = $DB->GetRow('select VC_apiID,VC_apiDomain,VC_apiUsername,VC_apiUserPwd from '. OT_dbPref .'vpsCompany where VC_ID='. $VT_companyID .'');

	if ($comRow['VC_apiID'] == 1){	// 星外
	
	}elseif ($comRow['VC_apiID'] == 2){	// 景安
		ApiJingan::$accessId	= $comRow['VC_apiUsername'];
		ApiJingan::$accessKey	= Encrypt::SyEnDe('de',$comRow['VC_apiUserPwd']);
		if (strlen($orderId) > 0){
			$dataArr = array(
				'ptype'		=> $ptype,
				'orderId'	=> $orderId,
				);
			$resArr = ApiJingan::VpsWorkId($dataArr);
			if (! $resArr['res']){
				JS::AlertEnd('尚未开通，请到景安平台开通下该机器，通过订单号（'. $orderId .'）获取业务编号失败（'. $resArr['note'] .'）');
			}
			$workId = $resArr['info']['bid'];
		}

		$dataArr = array(
			'ptype'		=> $ptype,
			'orderId'	=> $orderId,
			'workId'	=> $workId,
			);
		$resArr = ApiJingan::VpsSync2($dataArr);
		if (! $resArr['res']){
			JS::AlertEnd('尚未开通，请到景安平台开通下该机器，通过订单号/业务编号（'. $orderId .'/'. $workId .'）同步获取信息失败（'. $resArr['note'] .'）');
		}else{
			if (! strtotime($endTime)){
				$endTime = $resArr['info']['Extir']['overDate'];
			// }elseif (TimeDate::Diff('d',$endTime,$resArr['info']['Extir']['overDate']) < 0){
			//	$endTime = $resArr['info']['Extir']['overDate'];
			}
			$newArr = array();
			$newArr['VAU_state']		= 12;
			$newArr['VAU_apiID']		= $comRow['VC_apiID'];
			$newArr['VAU_workId']		= $workId;
			$newArr['VAU_workSign']		= $resArr['info']['Extir']['ip'];
			$newArr['VAU_vpsEndTime']	= $resArr['info']['Extir']['overDate'];
			$newArr['VAU_vpsUser']		= $resArr['info']['Extir']['userName'];
			$newArr['VAU_vpsPort']		= $resArr['info']['Extir']['remoteport'];
			$newArr['VAU_ipStr']		= AppJingan::GetIpList($resArr);
			$newArr['VAU_endTime']		= $endTime;
			if (strlen($orderId) > 0){
				$res2Arr = ApiJingan::VpsSync($dataArr);
				$newArr['VAU_vpsUser']	= $res2Arr['info']['user'];
				$newArr['VAU_vpsPwd']	= Encrypt::SyEnDe('en',$res2Arr['info']['pwd']);
				$newArr['VAU_vpsPort']	= $res2Arr['info']['remoteport'];
				$newArr['VAU_orderId']	= $orderId;
			}
			$retRes = $DB->UpdateParam('vpsApiUsers',$newArr,'VAU_ID='. $dataID);
			if ($retRes){
				echo('alert("检测开通成功，用户可以使用了。");document.location.reload();');
			}else{
				JS::AlertEnd('检测开通了，但更新记录失败。');
			}
		}
	
	}else{
		JS::AlertEnd('API接口不对');
	}

}


// 更新业务信息
function UpdateWorkInfo(){
	global $DB,$MB;

	$dataID		= OT::GetInt('dataID');

	$chkexe = $DB->query('select VAU_ID,VAU_proDataID,VAU_orderId,VAU_workId,VAU_endTime from '. OT_dbPref .'vpsApiUsers where VAU_ID='. $dataID);
	if (! $ru = $chkexe->fetch()){
		JS::AlertEnd('该云服务器不存在.');
	}
	$orderId	= $ru['VAU_orderId'];
	$workId		= $ru['VAU_workId'];
	$endTime	= $ru['VAU_endTime'];

	$proRow = $DB->GetRow('select VAD_typeID,VAD_ptype,VAD_pname,VAD_comProID,VAD_comServID from '. OT_dbPref .'vpsApiData where VAD_ID='. $ru['VAU_proDataID']);
	$ptype		= $proRow['VAD_ptype'];

	$VT_companyID = $DB->GetOne('select VT_companyID from '. OT_dbPref .'vpsType where VT_ID='. $proRow['VAD_typeID'] .'');

	$comRow = $DB->GetRow('select VC_apiID,VC_apiDomain,VC_apiUsername,VC_apiUserPwd from '. OT_dbPref .'vpsCompany where VC_ID='. $VT_companyID .'');

	if ($comRow['VC_apiID'] == 1){	// 星外
		JS::AlertEnd('该功能目前仅对景安VPS有效');

	}elseif ($comRow['VC_apiID'] == 2){	// 景安
		ApiJingan::$accessId	= $comRow['VC_apiUsername'];
		ApiJingan::$accessKey	= Encrypt::SyEnDe('de',$comRow['VC_apiUserPwd']);
		if (strlen($orderId) > 0){
			$dataArr = array(
				'ptype'		=> $ptype,
				'orderId'	=> $orderId,
				);
			$resArr = ApiJingan::VpsWorkId($dataArr);
			if (! $resArr['res']){
				JS::AlertEnd('尚未开通，请到景安平台开通下该机器，通过订单号（'. $orderId .'）获取业务编号失败（'. $resArr['note'] .'）');
			}
			$workId = $resArr['info']['bid'];
		}

		$dataArr = array(
			'ptype'		=> $ptype,
			'orderId'	=> $orderId,
			'workId'	=> $workId,
			);
		$resArr = ApiJingan::VpsSync2($dataArr);
		if (! $resArr['res']){
			JS::AlertEnd('尚未开通，请到景安平台开通下该机器，通过订单号/业务编号（'. $orderId .'/'. $workId .'）同步获取信息失败（'. $resArr['note'] .'）');
		}else{
			if (! strtotime($endTime)){
				$endTime = $resArr['info']['Extir']['overDate'];
			// }elseif (TimeDate::Diff('d',$endTime,$resArr['info']['Extir']['overDate']) < 0){
			//	$endTime = $resArr['info']['Extir']['overDate'];
			}
			$newArr = array();
			$newArr['VAU_apiID']		= $comRow['VC_apiID'];
			$newArr['VAU_workId']		= $workId;
			$newArr['VAU_workSign']		= $resArr['info']['Extir']['ip'];
			$newArr['VAU_vpsEndTime']	= $resArr['info']['Extir']['overDate'];
			$newArr['VAU_vpsUser']		= $resArr['info']['Extir']['userName'];
			$newArr['VAU_vpsPort']		= $resArr['info']['Extir']['remoteport'];
			$newArr['VAU_ipStr']		= AppJingan::GetIpList($resArr);
			$newArr['VAU_endTime']		= $endTime;
			$newArr['VAU_serverCode']	= '';
			$newArr['VAU_serverPwd']	= '';
			if (strlen($orderId) > 0){
				$res2Arr = ApiJingan::VpsSync($dataArr);
				$newArr['VAU_vpsUser']	= $res2Arr['info']['user'];
				if (strlen($res2Arr['info']['pwd']) > 2 && substr($res2Arr['info']['pwd'], -2) != '=='){
					$newArr['VAU_vpsPwd']	= Encrypt::SyEnDe('en',$res2Arr['info']['pwd']);
				}
				$newArr['VAU_vpsPort']	= $res2Arr['info']['remoteport'];
				$newArr['VAU_orderId']	= $orderId;
			}
			$retRes = $DB->UpdateParam('vpsApiUsers',$newArr,'VAU_ID='. $dataID);
			if ($retRes){
				JS::AlertEnd('更新业务信息成功。');
			}else{
				JS::AlertEnd('更新业务信息失败。');
			}
		}
	
	}else{
		JS::AlertEnd('API接口不对');
	}

}



// 提醒操作处理
function TixingDeal(){
	global $DB,$MB;

	$mudi2			= OT::GetStr('mudi2');
	$mode			= OT::GetStr('mode');
	$backURL		= OT::GetStr('backURL');
	$theme			= OT::GetStr('theme');
	$dataID			= OT::GetInt('dataID');
	$skipEndTime	= OT::GetInt('skipEndTime');
	$skipState		= OT::GetInt('skipState');
		if ($dataID <= 0){
			JS::AlertEnd('该记录ID错误.');
		}

	$dataexe = $DB->query('select VAT_type,VAT_dataID,VAT_payMode,VAT_price,VAT_cost,VAT_startTime,VAT_endTime,VAT_state from '. OT_dbPref .'vpsApiTixing where VAT_ID='. $dataID);
	if (! $row = $dataexe->fetch()){ JS::AlertEnd('该记录不存在。'); }
	if ($row['VAT_state'] != 0){ JS::AlertEnd('该记录状态不是待确认['. $row['VAT_state'] .']，不允许操作。'); }
	$backMoney = floatval($row['VAT_price']);

	$chkexe = $DB->query('select VAU_userID,VAU_username,VAU_apiID,VAU_proDataName,VAU_price,VAU_cost,VAU_vpsName,VAU_time,VAU_endTime,VAU_vpsEndTime,VAU_xufeiNum,VAU_state from '. OT_dbPref .'vpsApiUsers where VAU_ID='. $row['VAT_dataID']);
	if (! $rs = $chkexe->fetch()){ JS::AlertEnd('该机器记录不存在。'); }
	$userID = $rs['VAU_userID'];

	$judKaitong = false;
	if ($mode == 'yes'){
		$recomId = 0;
		$proArr = $listArr = array();
		$modeStr = '同意';
		if ($row['VAT_type'] == '开通'){
			if ($rs['VAU_apiID'] != 0){
				JS::AlertEnd('提醒开通只有无接口机器才能使用，有接口机器请手动开通。');
			}
			if ($skipEndTime == 0 && strtotime($row['VAT_endTime']) != strtotime($rs['VAU_endTime'])){
				JS::AlertEnd('原到期时间（'. $row['VAT_endTime'] .'）与机器当前到期时间（'. $rs['VAU_endTime'] .'）不匹配，不允许操作。');
			}
			if ($skipState == 0 && $rs['VAU_state'] != 5){ JS::AlertEnd('该机器状态不是“开通中”，禁止操作。'); }

			$judKaitong = true;

			$record = array();
			$record['VAU_state']	= 10;

			// 如有推荐人，推荐人推广佣金处理
			$vpsSysArr = Cache::PhpFile('vpsSys');
			if (strpos($vpsSysArr['VS_commArea'],'|vpsApiKaiAdmin|') !== false){
				$urs = $DB->GetRow('select UE_ID,UE_username,UE_recomId,UE_recomUser,UE_money from '. OT_dbPref .'users where UE_ID='. $rs['VAU_userID']);
				$userID		= $urs['UE_ID'];
				$username	= $urs['UE_username'];
				$recomId	= $urs['UE_recomId'];
				$recomUser	= $urs['UE_recomUser'];
				$userMoney	= floatval($urs['UE_money']);
				unset($urs);

				if ($recomId > 0){
					$urs = $DB->GetRow('select UE_makeMoney,UE_makingMoney from '. OT_dbPref .'users where UE_ID='. $recomId);
					$makeMoney	= floatval($urs['UE_makeMoney']);
					$makingMoney= floatval($urs['UE_makingMoney']);
					unset($urs);

					$userPrice	= $rs['VAU_price'];
					$proDataName= $rs['VAU_proDataName'];
					$vpsName	= $rs['VAU_vpsName'];
					$endTime	= $rs['VAU_endTime'];
					$proPrice	= abs($userPrice);
					$money = $proPrice * $vpsSysArr['VS_vpsApiKaiRate'];
					if ($money > $vpsSysArr['VS_vpsApiKaiMax']){ $money = $vpsSysArr['VS_vpsApiKaiMax']; }
					$proArr = array(
						'GI_source'			=> '前台',
						'GI_userID'			=> $recomId,
						'GI_username'		=> $recomUser,
						'GI_proUserID'		=> $userID,
						'GI_proUsername'	=> $username,
						'GI_proType'		=> 'vpsApi',
						'GI_proID'			=> $row['VAT_dataID'],
						'GI_proName'		=> $proDataName,
						'GI_proPrice'		=> $proPrice,
						'GI_vpsName'		=> $vpsName,
						'GI_endTime'		=> $endTime,
						'GI_mode'			=> '开通',
						'GI_rate'			=> $vpsSysArr['VS_vpsApiKaiRate'],
						'GI_money'			=> $money,
						);
					$listArr = array(
						'GH_makingMoney'	=> $makingMoney + $money,
						'GH_makeMoney'		=> $makeMoney,
						);
				}
			}

		}elseif ($row['VAT_type'] == '续费'){
			if ($rs['VAU_apiID'] != 0){
				JS::AlertEnd('提醒续费只有无接口机器才能使用，有接口机器请手动续费。');
			}
			if ($skipEndTime == 0 && strtotime($row['VAT_startTime']) != strtotime($rs['VAU_endTime'])){
				JS::AlertEnd('原到期时间（'. $row['VAT_startTime'] .'）与机器当前到期时间（'. $rs['VAU_endTime'] .'）不匹配，不允许操作。');
			}
			if ($skipState == 0 && $rs['VAU_state'] != 15){ JS::AlertEnd('该机器状态不是“续费中”，禁止操作。'); }

			$vpsEndTime = IdcArea::NewEndTime($row['VAT_payMode'], $rs['VAU_vpsEndTime']);

			$record = array();
			$record['VAU_payMode']		= $row['VAT_payMode'];
			$record['VAU_price']		= $row['VAT_price'];
			$record['VAU_cost']			= $row['VAT_cost'];
			$record['VAU_endTime']		= $row['VAT_endTime'];
			$record['VAU_vpsEndTime']	= $vpsEndTime;
			$record['VAU_xufeiNum']		= 'VAU_xufeiNum+1';
			$record['VAU_state']		= 10;

			// 如有推荐人，推荐人推广佣金处理
			$vpsSysArr = Cache::PhpFile('vpsSys');
			if (strpos($vpsSysArr['VS_commArea'],'|vpsApiXuAdmin|') !== false && $rs['VAU_xufeiNum'] < $vpsSysArr['VS_vpsApiXuNum']){
				$urs = $DB->GetRow('select UE_ID,UE_username,UE_recomId,UE_recomUser,UE_money from '. OT_dbPref .'users where UE_ID='. $rs['VAU_userID']);
				$userID		= $urs['UE_ID'];
				$username	= $urs['UE_username'];
				$recomId	= $urs['UE_recomId'];
				$recomUser	= $urs['UE_recomUser'];
				$userMoney	= floatval($urs['UE_money']);
				unset($urs);

				if ($recomId > 0){
					$urs = $DB->GetRow('select UE_makeMoney,UE_makingMoney from '. OT_dbPref .'users where UE_ID='. $recomId);
					$makeMoney	= floatval($urs['UE_makeMoney']);
					$makingMoney= floatval($urs['UE_makingMoney']);
					unset($urs);

					$userPrice	= $rs['VAU_price'];
					$proDataName= $rs['VAU_proDataName'];
					$vpsName	= $rs['VAU_vpsName'];
					$endTime	= $rs['VAU_endTime'];
					$proPrice	= abs($userPrice);
					$money = $proPrice * $vpsSysArr['VS_vpsApiXuRate'];
					if ($money > $vpsSysArr['VS_vpsApiXuMax']){ $money = $vpsSysArr['VS_vpsApiXuMax']; }
					$proArr = array(
						'GI_source'			=> '前台',
						'GI_userID'			=> $recomId,
						'GI_username'		=> $recomUser,
						'GI_proUserID'		=> $userID,
						'GI_proUsername'	=> $username,
						'GI_proType'		=> 'vpsApi',
						'GI_proID'			=> $row['VAT_dataID'],
						'GI_proName'		=> $proDataName,
						'GI_proPrice'		=> $proPrice,
						'GI_vpsName'		=> $vpsName,
						'GI_endTime'		=> $endTime,
						'GI_mode'			=> '续费',
						'GI_rate'			=> $vpsSysArr['VS_vpsApiXuRate'],
						'GI_money'			=> $money,
						);
					$listArr = array(
						'GH_makingMoney'	=> $makingMoney + $money,
						'GH_makeMoney'		=> $makeMoney,
						);
				}
			}

		}elseif ($row['VAT_type'] == '退款'){
			if ($skipState == 0 && $rs['VAU_state'] != 8){ JS::AlertEnd('该机器状态不是“退款中”，禁止操作。'); }
			if (OT::FloatCmp($backMoney,$rs['VAU_price']) != 0){
				JS::AlertEnd('提醒退款金额：'. $backMoney .'元与机器记录的价格：'. $rs['VAU_price'] .'元不一致，操作停止。');
			}

			// 如有推荐人，推荐人推广佣金处理
			$chkrs = $DB->GetRow('select * from '. OT_dbPref .'gainItem where GI_proID='. $row['VAT_dataID'] .' and GI_proType='. $DB->ForStr('vpsApi') .' order by GI_ID DESC limit 1');
			if ($chkrs){
				if ($chkrs['GI_money'] > 0 && strtotime($chkrs['GI_endTime']) > time()){
					$urs = $DB->GetRow('select UE_makeMoney,UE_makingMoney from '. OT_dbPref .'users where UE_ID='. $chkrs['GI_userID']);
					$makeMoney	= floatval($urs['UE_makeMoney']);
					$makingMoney= floatval($urs['UE_makingMoney']);
					unset($urs);

					$proArr = array(
						'GI_ID'				=> $chkrs['GI_ID'],
						'GI_source'			=> '前台',
						'GI_money'			=> 0,
						'GI_isPay'			=> 0,
						'GI_state'			=> 9
						);
					$listArr = array(
						'GH_userID'		=> $chkrs['GI_userID'],
						'GH_username'		=> $chkrs['GI_username'],
						'GH_proUserID'		=> $chkrs['GI_proUserID'],
						'GH_proUsername'	=> $chkrs['GI_proUsername'],
						'GH_proType'		=> $chkrs['GI_proType'],
						'GH_proID'			=> $chkrs['GI_proID'],
						'GH_proName'		=> $chkrs['GI_proName'],
						'GH_proPrice'		=> $chkrs['GI_proPrice'],
						'GH_vpsName'		=> $chkrs['GI_vpsName'],
						'GH_endTime'		=> $row['VAT_endTime'],
						'GH_mode'			=> '退款',
						'GH_money'			=> $chkrs['GI_money']*(-1),
						'GH_makingMoney'	=> $makingMoney - $chkrs['GI_money'],
						'GH_makeMoney'		=> $makeMoney,
						);
					AppGain::RevItemData($proArr, $listArr, '退款');
				}
			}
			unset($chkrs);

			$record = array();
			$record['VAU_state']		= 9;
			$record['VAU_isUserPay']	= 0;

		}else{
			JS::AlertEnd('VAT_type 信息不对。');
		}

		$result = $DB->UpdateParam('vpsApiUsers', $record, 'VAU_ID='. $row['VAT_dataID']);
		if ($result){
			$alertRes='成功';
			$dataArr = array();
			$dataArr['VAT_state']		= 1;
			$dataArr['VAT_adminID']		= $MB->mMbRow['MB_ID'];
			$dataArr['VAT_adminName']	= $MB->mMbRow['MB_realname'];
			$dataArr['VAT_adminTime']	= TimeDate::Get();
			$DB->UpdateParam('vpsApiTixing', $dataArr, 'VAT_ID='. $dataID);

			if (in_array($row['VAT_type'], array('开通','续费'))){
				if ($judKaitong){
					$DB->UpdateParam('users',array('UE_vpsApiNum'=>'UE_vpsApiNum+1'),'UE_ID='. $userID);
				}

				// 如有推荐人，推荐人推广佣金处理
				if ($recomId > 0 && count($proArr) > 0 && count($listArr) > 0){
					AppGain::AddItemData($proArr, $listArr);
				}
			}
		}else{
			$alertRes='失败';
		}

		$userMoney = floatval($DB->GetOne('select UE_money from '. OT_dbPref .'users where UE_ID='. $rs['VAU_userID']));

		$alertStr = '';
		$scoreArr = array();
		if (in_array($row['VAT_type'], array('开通','续费'))){
			$userGain = $backMoney - $row['VAT_cost'];
			if ($userGain < 0){ $userGain = 0; }
			$scoreArr['MR_money']		= 0;
			$scoreArr['MR_remMoney']	= -9;
			$scoreArr['MR_cost']		= $row['VAT_cost'];
			$scoreArr['MR_bank']		= '';
			$scoreArr['MR_note']		= $row['VAT_type'] .'审核通过！产品：'. $rs['VAU_proDataName'] .'；机器编码：'. $rs['VAU_vpsName'] .'；';
		}else{
			$userGain = $backMoney - $rs['VAU_cost'];
			if ($userGain > 0){ $userGain = 0; }
			$scoreArr['MR_money']		= $backMoney;
			$scoreArr['MR_remMoney']	= $userMoney + $backMoney;
			$scoreArr['MR_cost']		= $rs['VAU_cost'];
			$scoreArr['MR_bank']		= '账户余额';
			$scoreArr['MR_note']		= $row['VAT_type'] .'审核通过！产品：'. $rs['VAU_proDataName'] .'；机器编码：'. $rs['VAU_vpsName'] .'；退款：'. $backMoney .'元；';
		}
		$scoreArr['MR_userID']		= $rs['VAU_userID'];
		$scoreArr['MR_username']	= $rs['VAU_username'];
		$scoreArr['MR_dataID']		= $row['VAT_dataID'];
		$scoreArr['MR_dataName']	= $rs['VAU_vpsName'];
		$scoreArr['MR_type']		= 'vpsApi';
		$scoreArr['MR_type2']		= $row['VAT_type'];
		$scoreArr['MR_gain']		= $userGain;
		$scoreArr['MR_adminID']		= $MB->mMbRow['MB_ID'];
		$scoreArr['MR_adminName']	= $MB->mMbRow['MB_realname'];
		$mrRes = AppMoneyRecord::AddData($scoreArr);
			if (! $mrRes){
				$alertStr .= '\n财务信息记录失败（需要“财务基础包”插件支持）！';
			}elseif ($row['VAT_type'] == '退款'){
				$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money+'. $backMoney,'UE_payMoney'=>'UE_payMoney-'. $backMoney),'UE_ID='. $rs['VAU_userID']);
				if (! $result){
					JS::AlertBackEnd('用户退款处理失败，请刷新页面重试下。');
					$alertStr .= '\n用户原金额 '. $userMoney .' 元，退款 '. $backMoney .' 元，现金额 '. OT::NumFormat($userMoney + $backMoney) .' 元';
				}
			}

	}elseif ($mode == 'no'){
		$modeStr = '拒绝';
		if ($row['VAT_type'] == '开通'){
			if ($skipState == 0 && $rs['VAU_state'] != 5){ JS::AlertEnd('该机器状态不是“开通中”，禁止操作。'); }

			$record = array();
			$record['VAU_endTime']	= $rs['VAU_time'];
			$record['VAU_isUserPay']= 0;
			$record['VAU_state']	= 6;

		}elseif ($row['VAT_type'] == '续费'){
			if ($skipState == 0 && $rs['VAU_state'] != 15){ JS::AlertEnd('该机器状态不是“续费中”，禁止操作。'); }

			$record = array();
			$record['VAU_state']	= 10;

		}elseif ($row['VAT_type'] == '退款'){
			if ($skipState == 0 && $rs['VAU_state'] != 8){ JS::AlertEnd('该机器状态不是“退款中”，禁止操作。'); }
			if (OT::FloatCmp($backMoney,$rs['VAU_price']) != 0){
				JS::AlertEnd('提醒退款金额：'. $backMoney .'元与机器记录的价格：'. $rs['VAU_price'] .'元不一致，操作停止。');
			}

			$record = array();
			$record['VAU_state']	= 10;

		}else{
			JS::AlertEnd('VAT_type 信息不对。');
		}

		$result = $DB->UpdateParam('vpsApiUsers', $record, 'VAU_ID='. $row['VAT_dataID']);
		if ($result){
			$alertRes='成功';
			$dataArr = array();
			$dataArr['VAT_state']		= 2;
			$dataArr['VAT_adminID']		= $MB->mMbRow['MB_ID'];
			$dataArr['VAT_adminName']	= $MB->mMbRow['MB_realname'];
			$dataArr['VAT_adminTime']	= TimeDate::Get();
			$DB->UpdateParam('vpsApiTixing', $dataArr, 'VAT_ID='. $dataID);
		}else{
			$alertRes='失败';
		}

		$alertStr = '';
		$scoreArr = array();
		if (in_array($row['VAT_type'], array('开通','续费'))){
			$scoreArr['MR_money']		= $row['VAT_price'];
			$scoreArr['MR_remMoney']	= $userMoney + floatval($row['VAT_price']);
			$scoreArr['MR_note']		= $row['VAT_type'] .'被拒绝！产品：'. $rs['VAU_proDataName'] .'；机器编码：'. $rs['VAU_vpsName'] .'；';
		}else{
			$scoreArr['MR_money']		= 0;
			$scoreArr['MR_remMoney']	= -9;
			$scoreArr['MR_note']		= $row['VAT_type'] .'被拒绝！产品：'. $rs['VAU_proDataName'] .'；机器编码：'. $rs['VAU_vpsName'] .'；退款：'. $backMoney .'元；';
		}
		$scoreArr['MR_userID']		= $rs['VAU_userID'];
		$scoreArr['MR_username']	= $rs['VAU_username'];
		$scoreArr['MR_dataID']		= $row['VAT_dataID'];
		$scoreArr['MR_dataName']	= $rs['VAU_vpsName'];
		$scoreArr['MR_type']		= 'vpsApi';
		$scoreArr['MR_type2']		= $row['VAT_type'];
		$scoreArr['MR_bank']		= '账户余额';
		$scoreArr['MR_adminID']		= $MB->mMbRow['MB_ID'];
		$scoreArr['MR_adminName']	= $MB->mMbRow['MB_realname'];
		$mrRes = AppMoneyRecord::AddData($scoreArr);
			if (! $mrRes){
				$alertStr .= '\n财务信息记录失败（需要“财务基础包”插件支持）！';
			}elseif (in_array($row['VAT_type'], array('开通','续费'))){
				$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money+'. $row['VAT_price'],'UE_payMoney'=>'UE_payMoney-'. $row['VAT_price']),'UE_ID='. $rs['VAU_userID']);
				if (! $result){ $alertStr .= '\n用户余额扣款失败。'; }
			}

	}else{
		JS::AlertEnd('mode参数不对。');

	}

	echo('
	<script language="javascript" type="text/javascript">
	alert("'. $modeStr . $row['VAT_type'] .'处理'. $alertRes .'！'. $alertStr .'");
	');
	if ($mudi2 == 'det'){
		echo('parent.document.location.reload();');
	}else{
		echo('parent.$id("tixingData'. $dataID .'").style.display="none";');
	}
	echo('
	</script>
	');
}



// 批量删除
function MoreDel(){
	global $DB,$mudi,$menuFileID,$menuTreeID,$systemArr;

	$backURL	= OT::PostStr('backURL');
	$dataType	= OT::PostStr('dataType');
	$dataTypeCN	= OT::PostStr('dataTypeCN');
	$selDataID	= OT::Post('selDataID');

	$selCount = OT::NewCount($selDataID);
	if ($selCount <= 0){
		JS::AlertBackEnd('请先选择要删除的记录.');
	}

	$whereStr = '';
	for ($i=0; $i<$selCount; $i++){
		$whereStr .= ','. intval($selDataID[$i]);
	}
	if ($whereStr == ''){
		JS::AlertBackEnd('请先选择要删除的记录.');
	}

	$todayDate = TimeDate::Get('date');

	$alertStr = '';
	$dataNum = $failNum = $succNum = 0;
	$delIdArr = array();
	$delrec=$DB->query('select VAU_ID,VAU_proDataName,VAU_ipStr,VAU_endTime,VAU_state from '. OT_dbPref .'vpsApiUsers where VAU_ID in (0'. $whereStr .')');
	while ($row = $delrec->fetch()){
		$dataNum ++;
		$dayDiff = TimeDate::Diff('d', $row['VAU_endTime'], $todayDate);
		if ($dayDiff >= 8 || in_array($row['VAU_state'],array(0,3,6,9))){
			$succNum ++;
			$delIdArr[] = $row['VAU_ID'];

			AdmIdc::AddDelUsers('vpsApi', $row['VAU_ID']);

		}elseif ($dayDiff < 8){
			$failNum ++;
			if ($dayDiff < 0){ $endStr='还有'. abs($dayDiff) .'天才到期'; }else{ $endStr='只有'. $dayDiff .'天，不到8天'; }
			$alertStr .= '\n'. $failNum .'、'. $row['VAU_proDataName'] .'['. $row['VAU_ipStr'] .'] 到期时间（'. TimeDate::Get('date',$row['VAU_endTime']) .'）'. $endStr .'，不允许删除';

		}else{
			$failNum ++;
			$alertStr .= '\n'. $failNum .'、'. $row['VAU_proDataName'] .'['. $row['VAU_ipStr'] .'] 状态为 '. IdcInfo::State($row['VAU_state'],'cn') .'，不予许删除！';

		}
	}
	unset($delrec);

	if (count($delIdArr) > 0){
		$idStr = implode(',',$delIdArr);
		$DB->query('delete from '. OT_dbPref .'vpsApiUsers where VAU_ID in ('. $idStr .')');
		$DB->query('delete from '. OT_dbPref .'vpsApiTixing where VAT_dataID in ('. $idStr .')');
	}

	Adm::AddLog(array(
		'note'		=> '【'. $dataTypeCN .'】批量删除(共'. $dataNum .'条，成功'. $succNum .'条，失败'. $failNum .'条)！',
		));

	JS::AlertHrefEnd('批量删除(共'. $dataNum .'条，成功'. $succNum .'条，失败'. $failNum .'条).'. $alertStr,$backURL);

}



// 获取包销订单编号
function GetBaoxiaoOrder(){
	global $DB,$sysAdminArr;

	$proID		= OT::GetInt('proID');
	$num		= OT::GetInt('num');
		if ($num < 1){ $num = 1; }
	$month		= OT::GetInt('month');
		if ($month != 12){ $month = 1; }

	$proRow = $DB->GetRow('select VAD_companyID,VAD_pcountry,VAD_pname from '. OT_dbPref .'vpsApiData where VAD_ID='. $proID);
		if (! $proRow){ JS::AlertEnd('搜索不到产品信息'); }

	$comexe = $DB->query('select VC_apiID,VC_apiDomain,VC_apiUsername,VC_apiUserPwd from '. OT_dbPref .'vpsCompany where VC_ID='. $proRow['VAD_companyID']);
		if (! $rs3 = $comexe->fetch()){ JS::AlertEnd('搜索不到上级渠道商记录'); }

	ApiJingan::$accessId	= $rs3['VC_apiUsername'];
	ApiJingan::$accessKey	= Encrypt::SyEnDe('de',$rs3['VC_apiUserPwd']);
	ApiJingan::$urlMode		= $proRow['VAD_pcountry'];

	$dataArr = array(
		'pname'		=> $proRow['VAD_pname'],
		'buyNum'	=> $num,
		'yid'		=> $month
		);
	$resArr = ApiJingan::GetBaoxiaoOrder($dataArr);
	if (! $resArr['res']){
		if (strpos($resArr['note'],':1132}') !== false){
			JS::AlertEnd('获取包销订单编号出错（可能该型号没有包销）');
		}else{
			JS::AlertEnd('获取包销订单编号出错（'. $resArr['note'] .'）');
		}
	}
	$retStr = '【'. AppJingan::pnameCN($proRow['VAD_pname']) .'】<span style=\'color:red;\'>'. ($month == 12 ? '年' : '月') .'</span>包销订单号：'. implode(',',$resArr['info']);

	JS::DiyEnd('parent.$id("bxOrder").innerHTML="'. $retStr .'";');
	//JS::AlertEnd($retStr);
}


// 导出
function ExportDeal(){
	global $DB,$mudi,$menuFileID,$menuTreeID;

	$refProName		= OT::PostRegExpStr('refProName','sql');
	$refUsername	= OT::PostRegExpStr('refUsername','sql');
	$refQQ			= OT::PostRegExpStr('refQQ','sql');
	$refVpsName		= OT::PostRegExpStr('refVpsName','sql');
	$refState		= OT::PostInt('refState',-1);
	$refIpStr		= OT::PostRegExpStr('refIpStr','sql+.');
	$refAdminNote	= OT::PostRegExpStr('refAdminNote','sql');
	$refAdminName	= OT::PostRegExpStr('refAdminName','sql');
	$refDel			= OT::PostInt('refDel');
	$refMorePro		= OT::PostInt('refMorePro');
	$judOverDay		= OT::PostInt('judOverDay');
	$judLessDay		= OT::PostInt('judLessDay');
	$refMark		= OT::PostInt('refMark');
	$refNoMail		= OT::PostInt('refNoMail');
	$refNoPhone		= OT::PostInt('refNoPhone');
	$refNoWeixin	= OT::PostInt('refNoWeixin');
	$refApiRestart	= OT::PostInt('refApiRestart');
	$refApiManage	= OT::PostInt('refApiManage');
	$refDate1		= OT::PostStr('refDate1');
		if (! strtotime($refDate1)){ $refDate1=''; }
	$refDate2		= OT::PostStr('refDate2');
		if (! strtotime($refDate2)){ $refDate2=''; }
	$refEndDate1		= OT::PostStr('refEndDate1');
		if (strtotime($refEndDate1)==false){$refEndDate1='';}
	$refEndDate2		= OT::PostStr('refEndDate2');
		if (strtotime($refEndDate2)==false){$refEndDate2='';}
	$refVpsEndDate1		= OT::PostStr('refVpsEndDate1');
		if (strtotime($refVpsEndDate1)==false){$refVpsEndDate1='';}
	$refVpsEndDate2		= OT::PostStr('refVpsEndDate2');
		if (strtotime($refVpsEndDate2)==false){$refVpsEndDate2='';}
	$isExportAdmin	= OT::PostInt('isExportAdmin');

	$sqlFieldStr = 'VAU_ID,VAU_companyID,VAU_proDataID,VAU_proDataName,VAU_userID,VAU_username,VAU_vpsName,VAU_vpsEndTime,VAU_system,VAU_ipStr,VAU_vpsPort,VAU_vpsUser,VAU_vpsPwd,VAU_payMode,VAU_price,VAU_cost,VAU_time,VAU_endTime,VAU_state,VAU_adminNote,UE_realname,UE_qq,UE_ww,VAU_event,VAU_adminID,VAU_adminName';
	$SQLstr='select '. $sqlFieldStr .' from '. OT_dbPref .'vpsApiUsers as VAU left join '. OT_dbPref .'users as UE on VAU.VAU_userID=UE.UE_ID where 1=1';

	$refItemStr = '';
	if ($refProName!=''){ $SQLstr .= " and VAU_proDataName like '%". $DB->ForStr($refProName,false) ."%'"; $refItemStr .= '产品名称：'. $refProName .'；'; }
	if ($refUsername!=''){ $SQLstr .= " and VAU_username like '%". $DB->ForStr($refUsername,false) ."%'"; $refItemStr .= '用户名：'. $refUsername .'；'; }
	if ($refQQ!=''){ $SQLstr .= " and (UE_realname like '%". $DB->ForStr($refQQ,false) ."%' or UE_qq like '%". $DB->ForStr($refQQ,false) ."%' or UE_ww like '%". $DB->ForStr($refQQ,false) ."%')"; $refItemStr .= '昵称/QQ/旺旺：'. $refQQ .'；'; }
	if ($refVpsName!=''){ $SQLstr .= " and VAU_vpsName like '%". $DB->ForStr($refVpsName,false) ."%'"; $refItemStr .= '机器编码：'. $refVpsName .'；'; }
	if ($refState>-1){ $SQLstr .= ' and VAU_state='. $refState .''; $refItemStr .= '状态：'. IdcInfo::State($refState,'cn') .'；'; }
	if ($refIpStr!=''){ $SQLstr .= " and VAU_ipStr like '%". $DB->ForStr($refIpStr,false) ."%'"; $refItemStr .= 'IP地址：'. $refIpStr .'；'; }
	if ($refAdminNote!=''){ $SQLstr .= " and VAU_adminNote like '%". $DB->ForStr($refAdminNote,false) ."%'"; $refItemStr .= '内部备注：'. $refAdminNote .'；'; }
	if ($refAdminName!=''){ $SQLstr .= " and VAU_adminName like '%". $DB->ForStr($refAdminName,false) ."%'"; $refItemStr .= '操作员：'. $refAdminName .'；'; }
	if ($refDate1!=''){ $SQLstr .= ' and VAU_time>='. $DB->ForTime($refDate1); $refItemStr .= '开通日期开始：'. $refDate1 .'；'; }
	if ($refDate2!=''){ $SQLstr .= ' and VAU_time<'. $DB->ForTime(TimeDate::Add('d',1,$refDate2)); $refItemStr .= '开通日期结束：'. $refDate2 .'；'; }
	if ($refEndDate1!=''){ $SQLstr .= ' and VAU_endTime>='. $DB->ForTime($refEndDate1); $refItemStr .= '到期日期开始：'. $refEndDate1 .'；'; }
	if ($refEndDate2!=''){ $SQLstr .= ' and VAU_endTime<'. $DB->ForTime(TimeDate::Add('d',1,$refEndDate2)); $refItemStr .= '到期日期结束：'. $refEndDate2 .'；'; }
	if ($refVpsEndDate1!=''){ $SQLstr .= ' and VAU_vpsEndTime>='. $DB->ForTime($refVpsEndDate1); $refItemStr .= 'API到期开始：'. $refVpsEndDate1 .'；'; }
	if ($refVpsEndDate2!=''){ $SQLstr .= ' and VAU_vpsEndTime<'. $DB->ForTime(TimeDate::Add('d',1,$refVpsEndDate2)); $refItemStr .= 'API到期结束：'. $refVpsEndDate2 .'；'; }
	if ($refDel == 1){ $SQLstr .= ' and (VAU_endTime<='. $DB->ForTime(TimeDate::Add('d', -8, $todayDate)) .' or VAU_state in (0,3,6,9))'; $refItemStr .= '可删除记录：√；'; }
	if ($judOverDay == 1){
		$vpsSysArr = Cache::PhpFile('vpsSys');
		$SQLstr .= ' and to_days(VAU_endTime) - to_days(VAU_vpsEndTime) > '. $vpsSysArr['VS_overApiDay'];
		 $refItemStr .= '已付未续：√；';
	}elseif ($judLessDay == 1){
		$vpsSysArr = Cache::PhpFile('vpsSys');
		$SQLstr .= ' and to_days(VAU_vpsEndTime) - to_days(VAU_endTime) > '. $vpsSysArr['VS_lessApiDay'];
		 $refItemStr .= '未付已续：√；';
	}
	if ($refMark == 1){ $SQLstr .= ' and VAU_event like "%|mark|%"'; $refItemStr .= '星标：√；'; }
	if ($refNoMail == 1){ $SQLstr .= ' and VAU_event like "%|noMail|%"'; $refItemStr .= '禁邮：√；'; }
	if ($refNoPhone == 1){ $SQLstr .= ' and VAU_event like "%|noPhone|%"'; $refItemStr .= '禁短：√；'; }
	if ($refNoWeixin == 1){ $SQLstr .= ' and VAU_event like "%|noWeixin|%"'; $refItemStr .= '禁公：√；'; }
	if ($refApiRestart == 1){ $SQLstr .= ' and VAU_event like "%[restart]%"'; $refItemStr .= '重启：√；'; }
	if ($refApiManage == 1){ $SQLstr .= ' and VAU_event like "%[manage]%"'; $refItemStr .= '管理：√；'; }

	$retStr = '';
	$recordNum = 0;
	$loadexe = $DB->query($SQLstr .' order by '. ($isExportAdmin == 1 ? 'VAU_username' : 'VAU_endTime') .' ASC');
		if (! $row = $loadexe->fetch()){
			JS::AlertCloseEnd('没有搜索到记录，无需导出.');
		}

	$filename = '云服务器记录_'. TimeDate::Get('datetimeStr') .'.xls';
	$ua = $_SERVER['HTTP_USER_AGENT'];
	$encoded_filename = urlencode($filename);
	$encoded_filename = str_replace('+', '%20', $encoded_filename);
	if (preg_match('/MSIE/', $ua)) {
		header('Content-Disposition: attachment; filename="'. $encoded_filename .'"');
	} else if (preg_match("/Firefox/", $ua)) {
		header('Content-Disposition: attachment; filename*="utf8\'\''. $filename .'"');
	} else {
		header('Content-Disposition: attachment; filename="'. $filename .'"');
	}

	header('Content-Type: application/vnd.ms-excel; name="excel"');
	header('Content-type: application/octet-stream');
	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
	header('Pragma: no-cache');
	header('Expires: 0');

	$addiField = '';
	if ($isExportAdmin == 1){ $addiField = '<td>API到期日期</td><td>内部备注</td>'; }
	$retStr = '
		<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
		<head>
			<meta http-equiv=Content-Type content="text/html; charset=utf-8">
		</head>
		<body style="font-size:14px; font-family:simsun,"Microsoft YaHei";">
		<table border=1><head>'. $filename .'</head>
		<tr><td>编号</td><td>用户名</td><td>昵称</td><td>QQ</td><td>产品名称</td><td>机器编码</td><td>IP</td><td>价格</td><td>开通日期</td><td>到期日期</td>'. $addiField .'</tr>
		'; 

	do {
		$recordNum ++;
		$retStr .= '<tr><td>'. $recordNum .'</td><td>'. $row['VAU_username'] .'</td><td>'. $row['UE_realname'] .'</td><td>'. str_replace(',',"\r\n",$row['UE_qq']) .'</td><td>'. $row['VAU_proDataName'] .'</td><td>'. $row['VAU_vpsName'] .'</td><td>'. IdcArea::IpStr($row['VAU_ipStr'],"\r\n") .'</td><td>'. IdcInfo::PayMode($row['VAU_payMode']) .'：'. $row['VAU_price'] .'</td><td>'. $row['VAU_time'] .'</td><td>'. $row['VAU_endTime'] .'['. TimeDate::DiffDayCN($row['VAU_endTime']) .']' .'</td>'. ($isExportAdmin == 1 ? '<td>'. $row['VAU_vpsEndTime'] .'['. TimeDate::DiffDayCN($row['VAU_vpsEndTime']) .']' .'</td><td>'. $row['VAU_adminNote'] .'</td>' : '') .'</tr>';
	}while ($row = $loadexe->fetch());

	$retStr .= '
		</table>
		<div>共导出'. $recordNum .'条（查询条件 '. $refItemStr .'）</div>
		</body>
		</html>
		';

	echo($retStr);

}


// 更新API ID
function UpdateApiID(){
	global $DB,$MB;

	$apiID = $companyID = $dataNum = 0;
	$vpsexe = $DB->query('select VAU_ID,VAU_proDataID,VAU_proDataName,VAU_vpsName from '. OT_dbPref .'vpsApiUsers');
	while ($vpsRow = $vpsexe->fetch()){
		$dataNum ++;
		$proRow = $DB->GetRow('select VAD_typeID from '. OT_dbPref .'vpsApiData where VAD_ID='. $vpsRow['VAU_proDataID']);
			if (! $proRow){
				echo('<div>['. $vpsRow['VAU_vpsName'] .']'. $vpsRow['VAU_proDataName'] .' 产品ID【'. $vpsRow['VAU_proDataID'] .'】不存在</div>');
				continue;
			}

		$typeRow = $DB->GetRow('select VT_classID,VT_companyID from '. OT_dbPref .'vpsType where VT_ID='. $proRow['VAD_typeID'] .'');
			if (! $typeRow){
				echo('<div>['. $vpsRow['VAU_vpsName'] .']'. $vpsRow['VAU_proDataName'] .' 产品类型ID【'. $proRow['VAD_typeID'] .'】不存在</div>');
				continue;
			}
			if ($typeRow['VT_classID'] != 2){
				echo('<div>['. $vpsRow['VAU_vpsName'] .']'. $vpsRow['VAU_proDataName'] .' 该通道只处理云服务器的['. $typeRow['VT_classID'] .']</div>');
				continue;
			}
			$companyID = $typeRow['VT_companyID'];

		$comRow = $DB->GetRow('select VC_apiID from '. OT_dbPref .'vpsCompany where VC_ID='. $companyID .'');
			if (! $comRow){
				echo('<div>['. $vpsRow['VAU_vpsName'] .']'. $vpsRow['VAU_proDataName'] .' 上级渠道商记录ID['. $companyID .']不存在</div>');
				continue;
			}
			$apiID = $comRow['VC_apiID'];
		
		$result = $DB->UpdateParam('vpsApiUsers',array('VAU_apiID'=>$apiID,'VAU_companyID'=>$companyID),'VAU_ID='. $vpsRow['VAU_ID']);
			if (! $result){
				echo('<div>['. $vpsRow['VAU_vpsName'] .']'. $vpsRow['VAU_proDataName'] .' 更新失败</div>');
			}

	}
	unset($vpsexe);

	echo('<div>共更新 '. $dataNum .' 条记录</div>');
	
}


// API同步更新
function ApiUpdate(){
	global $DB;

	@ini_set('max_execution_time', 0);
	@set_time_limit(0); 

	echo('
	<title>云服务器 API同步更新</title>
	<div style="padding:15px 0;">云服务器 API同步更新 运行中...</div>
	');
	$runNum = 0;
	$hostCount = $DB->GetOne('select count(1) from '. OT_dbPref .'vpsApiUsers where VAU_apiID>=1 and (VAU_lastApiTime is null or VAU_lastApiTime<='. $DB->ForTime(TimeDate::Get('date')) .')');
	$hostexe = $DB->query('select VAU_ID,VAU_proDataName,VAU_vpsName from '. OT_dbPref .'vpsApiUsers where VAU_apiID>=1 and (VAU_lastApiTime is null or VAU_lastApiTime<='. $DB->ForTime(TimeDate::Get('date')) .') limit 20');	// ,VAU_lastApiTime order by VAU_lastApiTime ASC 
	if ($row = $hostexe->fetch()){
		Area::RunSecReload(3);
		do{
			$runNum ++;
			$retArr = AppIdcVps::Sync($row['VAU_ID'],'api');
				if ($retArr['res']){
					echo('<div>【成功】'. $row['VAU_vpsName'] .'</div>');
				}else{
					echo('<div>【失败】'. $row['VAU_vpsName'] .'['. $row['VAU_proDataName'] .']原因：'. $retArr['note'] .'</div>');
					$DB->UpdateParam('vpsApiUsers',array('VAU_lastApiTime'=>TimeDate::Get('date') .' 01:00:00'),'VAU_ID='. $row['VAU_ID']);
				}
		}while ($row = $hostexe->fetch());
	}else{
		echo('<div>今日无未执行的记录</div>');
	}
	unset($hostexe);

	echo('<div style="padding:15px 0;">执行了 '. $runNum .' 个记录，剩余 '. ($hostCount - $runNum) .' 个记录</div>');
}

?>